-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
22 lines (18 loc) · 738 Bytes
/
utils.py
File metadata and controls
22 lines (18 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
from glob import glob
def get_train_val_names(dataset_path, remove_names, radio=0.3):
train_names = []
val_names = []
dataset_paths = os.listdir(dataset_path)
for n in remove_names:
dataset_paths.remove(n)
for path in dataset_paths:
sub_dataset_path = os.path.join(dataset_path, path)
sub_dataset_names = glob(os.path.join(sub_dataset_path, '*.png'))
sub_dataset_len = len(sub_dataset_names)
val_names.extend(sub_dataset_names[:int(radio*sub_dataset_len)])
train_names.extend(sub_dataset_names[int(radio*sub_dataset_len):])
return {'train': train_names, 'val': val_names}
def check_folder(path):
if not os.path.exists(path):
os.mkdir(path)