-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsplit_car.py
More file actions
21 lines (19 loc) · 795 Bytes
/
split_car.py
File metadata and controls
21 lines (19 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
import os
import os.path as osp
import shutil
from tqdm import tqdm
img_list = np.genfromtxt('mat2txt.txt', dtype=str) # [num, img, cls, istest]
class_mappings = np.genfromtxt('label_map.txt', dtype=str)
class_mappings = {a[0]: a[1] for a in class_mappings}
for item in tqdm(img_list):
if bool(int(item[-1])):
cls_folder = osp.join('cars196', 'train', class_mappings[item[2]])
if not os.path.exists(cls_folder):
os.mkdir(cls_folder)
shutil.copy(item[1], osp.join(cls_folder, item[1].split('/')[-1]))
else:
cls_folder = osp.join('cars196', 'val', class_mappings[item[2]])
if not os.path.exists(cls_folder):
os.mkdir(cls_folder)
shutil.copy(item[1], osp.join(cls_folder, item[1].split('/')[-1]))