Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix when image_encode failed in im2rec.py (#4636)
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyetx authored and piiswrong committed Jan 11, 2017
1 parent 88e6106 commit dc859fb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/im2rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ def image_encode(args, i, item, q_out):
except Exception, e:
traceback.print_exc()
print('pack_img error:', item[1], e)
q_out.put((i, None, item))
return

try:
img = cv2.imread(fullpath, args.color)
except:
traceback.print_exc()
print('imread error trying to load file: %s ' % fullpath)
q_out.put((i, None, item))
return
if img is None:
print('imread read blank (None) image for file: %s' % fullpath)
q_out.put((i, None, item))
return
if args.center_crop:
if img.shape[0] > img.shape[1]:
Expand All @@ -134,6 +137,7 @@ def image_encode(args, i, item, q_out):
except Exception, e:
traceback.print_exc()
print('pack_img error on file: %s' % fullpath, e)
q_out.put((i, None, item))
return

def read_worker(args, q_in, q_out):
Expand Down Expand Up @@ -164,7 +168,8 @@ def write_worker(q_out, fname, working_dir):
while count in buf:
s, item = buf[count]
del buf[count]
record.write_idx(item[0], s)
if s is not None:
record.write_idx(item[0], s)

if count % 1000 == 0:
cur_time = time.time()
Expand Down

0 comments on commit dc859fb

Please sign in to comment.