Skip to content

Enable testing of ImageNet and MNIST models from classify.py#2359

Closed
dribnet wants to merge 2 commits intoBVLC:masterfrom
dribnet:classify-fix
Closed

Enable testing of ImageNet and MNIST models from classify.py#2359
dribnet wants to merge 2 commits intoBVLC:masterfrom
dribnet:classify-fix

Conversation

@dribnet
Copy link

@dribnet dribnet commented Apr 24, 2015

This simply re-introduces changes originally added in #735 by @petewarden to the current version of caffe.

This enables testing the ImageNet Caffe model from classify.py as described in the current wiki pages:

$ python python/classify.py --print_results examples/images/cat.jpg foo

Loading file: examples/images/cat.jpg
Classifying 1 inputs.
Done in 1.43 s.
[('tabby', '0.27353'), ('tiger cat', '0.23681'), ('Egyptian cat', '0.15175'), ('lynx', '0.12904'), ('kit fox', '0.04705')]
Saving results into foo

and also adds MNIST support:

$ ./train_lenet.sh
$ python python/classify.py --print_results \
  --model_def examples/mnist/lenet.prototxt \
  --pretrained_model examples/mnist/lenet_iter_10000.caffemodel \
  --force_grayscale --center_only \
  --labels_file data/mnist/mnist_words.txt \
  --images_dim 28,28 data/mnist/sample_digit.png resultsfile

Loading image file: data/mnist/sample_digit.png
Classifying 1 inputs.
Done in 0.05 s.
[('Four', '1.00000'), ('Zero', '0.00000'), ('One', '0.00000'), ('Two', '0.00000'), ('Three', '0.00000')]
Saving results into resultsfile

dribnet added 2 commits April 24, 2015 00:08
Resurrected changes first introduced in b360e2a.

This change enables testing the ImageNet Caffe model from
classify.py as described in the current wiki pages:

$ python python/classify.py --print_results examples/images/cat.jpg foo

Loading file: examples/images/cat.jpg
Classifying 1 inputs.
Done in 1.43 s.
[('tabby', '0.27353'), ('tiger cat', '0.23681'), ('Egyptian cat', '0.15175'), ('lynx', '0.12904'), ('kit fox', '0.04705')]
Saving results into foo
Resurrected work done introduced f9cc18c and 961b00e.

Here's an example invocation after this change:

$ ./train_lenet.sh

$ python python/classify.py --print_results \
  --model_def examples/mnist/lenet.prototxt \
  --pretrained_model examples/mnist/lenet_iter_10000.caffemodel \
  --force_grayscale --center_only \
  --labels_file data/mnist/mnist_words.txt \
  --images_dim 28,28 data/mnist/sample_digit.png resultsfile

Loading image file: data/mnist/sample_digit.png
Classifying 1 inputs.
Done in 0.05 s.
[('Four', '1.00000'), ('Zero', '0.00000'), ('One', '0.00000'), ('Two', '0.00000'), ('Three', '0.00000')]
Saving results into resultsfile
@dribnet dribnet changed the title Classify fix Enable testing of ImageNet Caffe and MNIST from classify.py Apr 24, 2015
@dribnet dribnet changed the title Enable testing of ImageNet Caffe and MNIST from classify.py Enable testing of ImageNet and MNIST models from classify.py Apr 24, 2015
@kkarnatak
Copy link

@dribnet I am getting an error NameError: global name 'scores' is not defined while executing classify.py using --print_results argument. I have followed all the steps as suggested in your first post on this thread, and have also googled elsewhere, but no luck. Did you face this kinda issue as well?

@kkarnatak
Copy link

@dribnet I got it. I used the files associated with this thread and replaced "scores" with "predictions".

For reference:

indices = (-predictions[0]).argsort()[:5]
predicted_labels = labels[indices]

Thanks.

@shelhamer
Copy link
Member

Closing as caffe.Classifier is soon to be deprecated. Thanks for polishing the script as it was all the same.

@shelhamer shelhamer closed this Apr 14, 2017
}
for l in f.readlines()
])
labels = labels_df.sort('synset_id')['name'].values
Copy link

@rajasekharponakala rajasekharponakala Dec 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments