-
Notifications
You must be signed in to change notification settings - Fork 1
/
imglist_generator.py
43 lines (41 loc) · 1.25 KB
/
imglist_generator.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
import os
'''
path="./data/images_classic/cinic/valid"
save_path="./data/benchmark_imglist/cifar10/val_cinic10.txt"
prefix="cinic/valid/"
category=["airplane","automobile","bird","cat","deer","dog","frog","horse","ship","truck"]
with open(save_path,'a') as f:
for name in category:
label=category.index(name)
sub_path=path+'/'+name
files=os.listdir(sub_path)
for file in files:
line=prefix+name+'/'+file+' '+str(label)+'\n'
f.write(line)
f.close()
'''
path="./data/images_classic/cifar100c"
save_path="./data/benchmark_imglist/cifar100/test_cifar100c.txt"
prefix="cifar100c/"
files=os.listdir(path)
with open(save_path,'a') as f:
for file in files:
splits=file.split("_")
label=(splits[1].split("."))[0]
line=prefix+file+" "+label+'\n'
f.write(line)
f.close()
'''
path="./data/images_largescale/imagenet_v2"
save_path="./data/benchmark_imglist/imagenet/test_imagenetv2.txt"
prefix="imagenet_v2/"
with open(save_path,'a') as f:
for i in range(0,1000):
label=str(i)
sub_path=path+'/'+label
files=os.listdir(sub_path)
for file in files:
line=prefix+label+'/'+file+' '+label+'\n'
f.write(line)
f.close()
'''