-
Notifications
You must be signed in to change notification settings - Fork 6
/
scripts.py
executable file
·62 lines (49 loc) · 1.35 KB
/
scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import glob
import os
import shutil
def gen_lst_from_fig(data_path, list):
ids = glob.glob(os.path.join(data_path, '*.png'))
ids.sort()
lst = []
for item in ids:
item = item.strip()
id = item.split('/')[-1]
lst.append([id, ])
# write list
target = open(list, 'w')
for line in lst:
print('\t'.join(line), file=target)
# tag
print('Done!')
def gen_lst_from_txt(source_lst, target_lst):
fid = open(source_lst, 'r')
lst = []
for item in fid.readlines():
img, label = item.strip().split(' ')
lst.append([label, ])
# write list
target = open(target_lst, 'w')
for line in lst:
print('\t'.join(line), file=target)
# tag
print('Done!')
def copy_desired_imgs(data_path, save_path, lst):
fid = open(lst, 'r')
# save path
if not os.path.exists(save_path):
os.makedirs(save_path)
for line in fid.readlines():
id = line.strip()
source_path = os.path.join(data_path, id)
target_path = os.path.join(save_path, id)
shutil.copy(source_path, target_path)
# tag
print('Done!')
if __name__ == '__main__':
DATA_PATH = ''
LIST = ''
SAVE_PATH = ''
TARGET = ''
# gen_lst_from_fig(DATA_PATH, LIST)
# copy_desired_imgs(DATA_PATH, SAVE_PATH, LIST)
# gen_lst_from_txt(LIST, TARGET)