-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgen_image_list.py
More file actions
56 lines (45 loc) · 1.33 KB
/
gen_image_list.py
File metadata and controls
56 lines (45 loc) · 1.33 KB
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
#!/usr/bin/env python
"""
@file gen_image_list.py
@brief generate image list
@author Tairui Chen
"""
# http://stackoverflow.com/questions/2584589/search-jpeg-files-using-python
import os
import sys
import csv
def main():
# collect argvs
task = "test"
assert task in ["train", "test"]
# sample_submission_file = sys.argv[2]
image_folder = "C:/Users/cht2pal/Downloads/weather/test"
file_out = "C:/Users/cht2pal/Desktop/test_list"
# read in header
#header = csv.reader( file(sample_submission_file) ).next()
#header = header[1:]
# make image list
img_lst = []
cnt = 0
# if task == "train":
# for i in xrange(len(header)):
# lst = os.listdir(image_folder + header[i])
# for img in lst:
# img_lst.append((header[i] + '/' + img, i))
# cnt += 1
# else:
lst = os.listdir(image_folder)
cls = 0
for folder in lst:
imglst = os.listdir(image_folder+'/'+folder)
for img in imglst:
img_lst.append(((image_folder+'/'+folder+'/'+img), cls))
cnt += 1
cls += 1
# write
with open(file_out, "w") as f:
writer_ = csv.writer(f, delimiter='\t', lineterminator='\n')
for item in img_lst:
writer_.writerow(item)
if __name__ == "__main__":
main()