Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions extractbgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

14 changes: 7 additions & 7 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])),
Expand All @@ -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,
Expand All @@ -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

Expand Down