diff --git a/detect.py b/detect.py index 7182fc6..6d9d1e1 100755 --- a/detect.py +++ b/detect.py @@ -89,7 +89,7 @@ def detect(im, param_vals): y_vals = [] for scaled_im in scaled_ims: feed_dict = {x: numpy.stack([scaled_im])} - feed_dict.update(dict(zip(params, param_vals))) + feed_dict.update(dict(list(zip(params, param_vals)))) y_vals.append(sess.run(y, feed_dict=feed_dict)) # Interpret the results in terms of bounding boxes in the input image. @@ -141,7 +141,7 @@ def _group_overlapping_rectangles(matches): num_groups += 1 groups = collections.defaultdict(list) - for idx, group in match_to_group.items(): + for idx, group in list(match_to_group.items()): groups[group].append(matches[idx]) return groups @@ -159,7 +159,7 @@ def post_process(matches): """ groups = _group_overlapping_rectangles(matches) - for group_matches in groups.values(): + for group_matches in list(groups.values()): mins = numpy.stack(numpy.array(m[0]) for m in group_matches) maxs = numpy.stack(numpy.array(m[1]) for m in group_matches) present_probs = numpy.array([m[2] for m in group_matches]) @@ -184,8 +184,8 @@ def letter_probs_to_code(letter_probs): for pt1, pt2, present_prob, letter_probs in post_process( detect(im_gray, param_vals)): - pt1 = tuple(reversed(map(int, pt1))) - pt2 = tuple(reversed(map(int, pt2))) + pt1 = tuple(reversed(list(map(int, pt1)))) + pt2 = tuple(reversed(list(map(int, pt2)))) code = letter_probs_to_code(letter_probs) diff --git a/extractbgs.py b/extractbgs.py index 6d1461b..e017da7 100755 --- a/extractbgs.py +++ b/extractbgs.py @@ -62,10 +62,10 @@ def extract_backgrounds(archive_name): t = tarfile.open(name=archive_name) def members(): - m = t.next() + m = next(t) while m: yield m - m = t.next() + m = next(t) index = 0 for m in members(): if not m.name.endswith(".jpg"): @@ -85,7 +85,7 @@ def members(): if im.shape[0] > 256: im = cv2.resize(im, (256, 256)) fname = "bgs/{:08}.jpg".format(index) - print fname + print(fname) rc = cv2.imwrite(fname, im) if not rc: raise Exception("Failed to write file {}".format(fname)) diff --git a/gen.py b/gen.py index 75660d0..c1c688c 100755 --- a/gen.py +++ b/gen.py @@ -287,6 +287,6 @@ def generate_ims(): for img_idx, (im, c, p) in enumerate(im_gen): fname = "test/{:08d}_{}_{}.png".format(img_idx, c, "1" if p else "0") - print fname + print(fname) cv2.imwrite(fname, im * 255.) diff --git a/train.py b/train.py index 162a8bd..c4c8240 100755 --- a/train.py +++ b/train.py @@ -69,7 +69,7 @@ def read_data(img_glob): def unzip(b): - xs, ys = zip(*b) + xs, ys = list(zip(*b)) xs = numpy.array(xs) ys = numpy.array(ys) return xs, ys @@ -202,11 +202,11 @@ def do_report(): r[3] < 0.5))) r_short = (r[0][:190], r[1][:190], r[2][:190], r[3][:190]) for b, c, pb, pc in zip(*r_short): - print "{} {} <-> {} {}".format(vec_to_plate(c), pc, - vec_to_plate(b), float(pb)) + print("{} {} <-> {} {}".format(vec_to_plate(c), pc, + vec_to_plate(b), float(pb))) num_p_correct = numpy.sum(r[2] == r[3]) - print ("B{:3d} {:2.02f}% {:02.02f}% loss: {} " + print(("B{:3d} {:2.02f}% {:02.02f}% loss: {} " "(digits: {}, presence: {}) |{}|").format( batch_idx, 100. * num_correct / (len(r[0])), @@ -215,7 +215,7 @@ def do_report(): r[4], r[5], "".join("X "[numpy.array_equal(b, c) or (not pb and not pc)] - for b, c, pb, pc in zip(*r_short))) + for b, c, pb, pc in zip(*r_short)))) def do_batch(): sess.run(train_step, @@ -240,9 +240,9 @@ def do_batch(): if batch_idx % report_steps == 0: batch_time = time.time() if last_batch_idx != batch_idx: - print "time for 60 batches {}".format( + print("time for 60 batches {}".format( 60 * (last_batch_time - batch_time) / - (last_batch_idx - batch_idx)) + (last_batch_idx - batch_idx))) last_batch_idx = batch_idx last_batch_time = batch_time