Skip to content

Commit

Permalink
More fault tolerant on lists of images
Browse files Browse the repository at this point in the history
  • Loading branch information
dpressel committed Jan 9, 2017
1 parent 6b85927 commit c5d6f46
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions guess.py
Expand Up @@ -54,6 +54,14 @@ def one_of(fname, types):
return True
return False

def resolve_file(fname):
if os.path.exists(fname): return fname
for suffix in ('.jpg', '.png', '.JPG', '.PNG', '.jpeg'):
cand = fname + suffix
if os.path.exists(cand):
return cand
return None

def classify(sess, label_list, softmax_output, coder, images, image_file):

print('Running file %s' % image_file)
Expand Down Expand Up @@ -138,10 +146,18 @@ def main(argv=None): # pylint: disable=unused-argument
writer = csv.writer(output)
writer.writerow(('file', 'label', 'score'))


for f in files:
best_choice = classify(sess, label_list, softmax_output, coder, images, f)
if writer is not None:
writer.writerow((f, best_choice[0], '%.2f' % best_choice[1]))
image_file = resolve_file(f)

if image_file is None: continue

try:
best_choice = classify(sess, label_list, softmax_output, coder, images, image_file)
if writer is not None:
writer.writerow((f, best_choice[0], '%.2f' % best_choice[1]))
except Exception:
print('Failed to run image %s ' % image_file)

if output is not None:
output.close()
Expand Down

0 comments on commit c5d6f46

Please sign in to comment.