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