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

Commit

Permalink
Better error messaging in im2rec.py tool (#3942)
Browse files Browse the repository at this point in the history
  • Loading branch information
leopd authored and piiswrong committed Nov 23, 2016
1 parent d8e3f49 commit 2205df6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tools/im2rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import cv2
import time
import traceback


def list_image(root, recursive, exts):
Expand Down Expand Up @@ -75,13 +76,15 @@ def read_list(path_in):
yield item

def image_encode(args, item, q_out):
fullpath = os.path.join(args.root, item[1])
try:
img = cv2.imread(os.path.join(args.root, item[1]), args.color)
img = cv2.imread(fullpath, args.color)
except:
print('imread error:', item[1])
traceback.print_exc()
print('imread error trying to load file: %s ' % fullpath)
return
if img is None:
print('read none error:', item[1])
print('imread read blank (None) image for file: %s' % fullpath)
return
if args.center_crop:
if img.shape[0] > img.shape[1]:
Expand All @@ -104,8 +107,9 @@ def image_encode(args, item, q_out):
try:
s = mx.recordio.pack_img(header, img, quality=args.quality, img_fmt=args.encoding)
q_out.put((s, item))
except Exception, e:
print('pack_img error:', item[1], e)
except Exception:
traceback.print_exc()
print('pack_img error on file: %s' % fullpath)
return

def read_worker(args, q_in, q_out):
Expand Down

0 comments on commit 2205df6

Please sign in to comment.