forked from computerhistory/AlexNet-Source-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-big-imgnet.py
More file actions
executable file
·40 lines (35 loc) · 1.2 KB
/
fix-big-imgnet.py
File metadata and controls
executable file
·40 lines (35 loc) · 1.2 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
import os
import sys
from PIL import Image
from StringIO import StringIO
from util import *
src = '/ais/gobi3/u/ilya/jpg_valid_2010_85/'
dst = '/ais/gobi3/u/kriz/lsvrc-2010-jpg/'
BATCH_SIZE = 1024
def save_batch(c_strings, c_labels, c_wnids, out_b):
pickle(os.path.join(dst, 'data_batch_%d' % out_b), (c_strings, c_labels, c_wnids))
return out_b + 1
if __name__ == "__main__":
c_strings = []
c_labels = []
c_wnids = []
out_b = 2000
for b in xrange(49):
failed = 0
strings, sizes, labels = unpickle(os.path.join(src, '%s' % b))
for s,l in zip(strings, labels):
try:
im = Image.open(StringIO(s)).convert('RGB')
c_strings += [s]
c_labels += [l[1]]
c_wnids += [l[0]]
if len(c_strings) == BATCH_SIZE:
out_b = save_batch(c_strings, c_labels, c_wnids, out_b)
c_strings = []
c_labels = []
c_wnids = []
except IOError,e:
failed += 1
print "Batch %d failed: %d" % (b, failed)
if len(c_strings) > 0:
save_batch(c_strings, c_labels, c_wnids, out_b)