-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_val.py
40 lines (29 loc) · 1.05 KB
/
train_val.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
import os
import numpy as np
root = '/imagenet/2011/'
img_label = {}
val = []
for (par_curpath, par_dirnam, par_filnam) in os.walk(os.path.join(root, 'train')):
par_dirnam.sort()
for i in range(len(par_dirnam)):
for (child_curpath, child_dirnam, child_filnam) in os.walk(root + 'train/' + par_dirnam[i]):
child_filnam.sort()
for j in range(len(child_filnam)):
img_label[par_dirnam[i] + '/' + child_filnam[j]] = i
f = open(os.path.join(root, 'train.txt'),'wb')
keylist = img_label.keys()
keylist.sort()
for i in sorted(img_label):
f.write(i + ' ' + str(img_label[i]) + '\n')
f.close()
#with open('/rfcn/py-R-FCN/caffe/data/ilsvrc12/val.txt') as file:
# filedata = file.read()
f = open('/rfcn/py-R-FCN/caffe/data/ilsvrc12/val.txt').xreadlines()
for l in f:
new = l.replace('ILSVRC2012_', 'ILSVRC2011_')
val.append(new)
f2 = open(os.path.join(root, 'val.txt'), 'wb')
for i in val:
f2.write(i)
f2.close()
f.close()