Skip to content

Commit

Permalink
Use image limit value for "Classify/Test Many"
Browse files Browse the repository at this point in the history
Previously, it was only used for "Top N Predictions"
  • Loading branch information
lukeyeager committed Feb 22, 2016
1 parent bde1a7a commit e7ad928
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
8 changes: 8 additions & 0 deletions digits/model/images/classification/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ def classify_many():
else:
image_folder = None

if 'num_test_images' in flask.request.form and flask.request.form['num_test_images'].strip():
num_test_images = int(flask.request.form['num_test_images'])
else:
num_test_images = None

epoch = None
if 'snapshot_epoch' in flask.request.form:
epoch = float(flask.request.form['snapshot_epoch'])
Expand Down Expand Up @@ -364,6 +369,9 @@ def classify_many():
except utils.errors.LoadImageError as e:
print e

if num_test_images is not None and len(images) >= num_test_images:
break

if not len(images):
raise werkzeug.exceptions.BadRequest(
'Unable to load any images from the file')
Expand Down
9 changes: 8 additions & 1 deletion digits/model/images/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def infer_many():
else:
image_folder = None

if 'num_test_images' in flask.request.form and flask.request.form['num_test_images'].strip():
num_test_images = int(flask.request.form['num_test_images'])
else:
num_test_images = None

epoch = None
if 'snapshot_epoch' in flask.request.form:
epoch = float(flask.request.form['snapshot_epoch'])
Expand Down Expand Up @@ -326,7 +331,6 @@ def infer_many():
try:
if not utils.is_url(path) and image_folder and not os.path.isabs(path):
path = os.path.join(image_folder, path)
print path
image = utils.image.load_image(path)
image = utils.image.resize_image(image, height, width,
channels = channels,
Expand All @@ -337,6 +341,9 @@ def infer_many():
except utils.errors.LoadImageError as e:
print e

if num_test_images is not None and len(images) >= num_test_images:
break

if not len(images):
raise werkzeug.exceptions.BadRequest(
'Unable to load any images from the file')
Expand Down
10 changes: 5 additions & 5 deletions digits/templates/models/images/classification/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ <h3>Test a list of images</h3>
<input type="text" id="image_folder" name="image_folder" class="form-control autocomplete_path">
<small>Relative paths in the text file will be prepended with this value before reading</small>
</div>
<div class="form-group">
<label for="num_test_images" class="control-label">Number of images use from the file</label>
<input type="text" id="num_test_images" name="num_test_images" class="form-control" placeholder="All">
<small>Leave blank to use all</small>
</div>
<button name="classify-many-btn"
formaction="{{url_for('digits.model.images.classification.views.classify_many', job_id=job.id())}}"
formmethod="post"
Expand All @@ -199,11 +204,6 @@ <h3>Test a list of images</h3>
data-container="body"
title="Classify a list of images and show the top 5 category predictions for each."
></span>
<div class="form-group">
<label for="num_test_images" class="control-label">Number of images use from the file</label>
<input type="text" id="num_test_images" name="num_test_images" class="form-control" value="100" placeholder="All">
<small>Leave blank to use all</small>
</div>
<div class="form-group">
<label for="top_n" class="control-label">Number of images to show per category</label>
<input type="text" id="top_n" name="top_n" class="form-control" placeholder="9">
Expand Down
5 changes: 5 additions & 0 deletions digits/templates/models/images/generic/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ <h3>Test a list of images</h3>
<input type="text" id="image_folder" name="image_folder" class="form-control autocomplete_path">
<small>Relative paths in the text file will be prepended with this value before reading</small>
</div>
<div class="form-group">
<label for="num_test_images" class="control-label">Number of images use from the file</label>
<input type="text" id="num_test_images" name="num_test_images" class="form-control" placeholder="All">
<small>Leave blank to use all</small>
</div>
<button name="infer-many-btn"
formaction="{{url_for('digits.model.images.generic.views.infer_many', job_id=job.id())}}"
formmethod="post"
Expand Down

0 comments on commit e7ad928

Please sign in to comment.