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

Commit

Permalink
Fix Python 3 compatibilities (#6908)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo authored and piiswrong committed Jul 3, 2017
1 parent 00b0f95 commit 998378a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tools/im2rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import time
import traceback

if sys.version_info[0] == 3:
xrange = range

try:
import multiprocessing
except ImportError:
Expand Down Expand Up @@ -89,7 +92,7 @@ def read_list(path_in):
continue
try:
item = [int(line[0])] + [line[-1]] + [float(i) for i in line[1:-1]]
except Exception, e:
except Exception as e:
print('Parsing lst met error for %s, detail: %s' %(line, e))
continue
yield item
Expand All @@ -108,7 +111,7 @@ def image_encode(args, i, item, q_out):
img = fin.read()
s = mx.recordio.pack(header, img)
q_out.put((i, s, item))
except Exception, e:
except Exception as e:
traceback.print_exc()
print('pack_img error:', item[1], e)
q_out.put((i, None, item))
Expand Down Expand Up @@ -142,7 +145,7 @@ def image_encode(args, i, item, q_out):
try:
s = mx.recordio.pack_img(header, img, quality=args.quality, img_fmt=args.encoding)
q_out.put((i, s, item))
except Exception, e:
except Exception as e:
traceback.print_exc()
print('pack_img error on file: %s' % fullpath, e)
q_out.put((i, None, item))
Expand Down Expand Up @@ -279,8 +282,11 @@ def parse_args():
write_process.join()
else:
print('multiprocessing not available, fall back to single threaded encoding')
import Queue
q_out = Queue.Queue()
try:
import Queue as queue
except ImportError:
import queue
q_out = queue.Queue()
fname = os.path.basename(fname)
fname_rec = os.path.splitext(fname)[0] + '.rec'
fname_idx = os.path.splitext(fname)[0] + '.idx'
Expand Down

0 comments on commit 998378a

Please sign in to comment.