diff --git a/1.png b/1.png new file mode 100644 index 0000000..1ce8061 Binary files /dev/null and b/1.png differ diff --git a/212.png b/212.png new file mode 100644 index 0000000..446f913 Binary files /dev/null and b/212.png differ diff --git a/27.jpg b/27.jpg new file mode 100644 index 0000000..b56ed7b Binary files /dev/null and b/27.jpg differ diff --git a/31.jpg b/31.jpg new file mode 100644 index 0000000..3fc61a8 Binary files /dev/null and b/31.jpg differ diff --git a/7.jpg b/7.jpg new file mode 100644 index 0000000..283ef88 Binary files /dev/null and b/7.jpg differ 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..c96c875 100755 --- a/extractbgs.py +++ b/extractbgs.py @@ -43,7 +43,7 @@ def im_from_file(f): a = numpy.asarray(bytearray(f.read()), dtype=numpy.uint8) - return cv2.imdecode(a, cv2.CV_LOAD_IMAGE_GRAYSCALE) + return cv2.imdecode(a, cv2.IMREAD_GRAYSCALE) def extract_backgrounds(archive_name): @@ -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..8e03fde 100755 --- a/gen.py +++ b/gen.py @@ -218,7 +218,7 @@ def generate_bg(num_bg_images): found = False while not found: fname = "bgs/{:08d}.jpg".format(random.randint(0, num_bg_images - 1)) - bg = cv2.imread(fname, cv2.CV_LOAD_IMAGE_GRAYSCALE) / 255. + bg = cv2.imread(fname, cv2.IMREAD_GRAYSCALE) / 255. if (bg.shape[1] >= OUTPUT_SHAPE[1] and bg.shape[0] >= OUTPUT_SHAPE[0]): found = True @@ -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..b665287 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 @@ -126,9 +126,9 @@ def get_loss(y, y_): # Calculate the loss from digits being incorrect. Don't count loss from # digits that are in non-present plates. digits_loss = tf.nn.softmax_cross_entropy_with_logits( - tf.reshape(y[:, 1:], + logits=tf.reshape(y[:, 1:], [-1, len(common.CHARS)]), - tf.reshape(y_[:, 1:], + labels=tf.reshape(y_[:, 1:], [-1, len(common.CHARS)])) digits_loss = tf.reshape(digits_loss, [-1, 7]) digits_loss = tf.reduce_sum(digits_loss, 1) @@ -137,7 +137,7 @@ def get_loss(y, y_): # Calculate the loss from presence indicator being wrong. presence_loss = tf.nn.sigmoid_cross_entropy_with_logits( - y[:, :1], y_[:, :1]) + logits=y[:, :1], labels=y_[:, :1]) presence_loss = 7 * tf.reduce_sum(presence_loss) return digits_loss, presence_loss, digits_loss + presence_loss @@ -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