Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typos pull request #121

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
Binary file added 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 212.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 27.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 31.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
4 changes: 2 additions & 2 deletions extractbgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down 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.)

20 changes: 10 additions & 10 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 @@ -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)
Expand All @@ -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
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