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

Add MNIST support to classify.py script #735

Closed
wants to merge 3 commits into from

Conversation

petewarden
Copy link

For a beginner's guide to Caffe I'm working on, I need a simple way for newbies to train their own network, and then try it out for themselves. The MNIST documentation is great for the training part, but the python scripts for running forward prediction on images were missing a couple of features I needed:

  • Human-readable output. The only option was to save to a serialized file which didn't give any indication of how well the recognition process had worked. To solve this I followed the web demo example, adding a --print_results option that then pulls in a labels text file set by --labels_file (defaulting to the Imagenet one) and writing out the top five scoring categories. I also added a simple labels file for the MNIST results.
  • Grayscale support. Several places in the scripts assume there will be three channels, so I had to add a --force_grayscale option that ensures the single-channel image that MNIST expects is created, and add some logic to avoid altering that (and subtracting a mean image) when the option is in effect.

To test that it didn't break the existing Imagenet functionality, I've been running this command:
python python/classify.py --print_results examples/images/cat.jpg foo

The results continue to be the expected 'kit fox' label.

Running an MNIST network created from the tutorial against a sample image is done with the command line:
python python/classify.py --print_results --model_def examples/mnist/lenet.prototxt --pretrained_model examples/mnist/lenet_iter_10000 --force_grayscale --center_only --labels_file data/mnist/mnist_words.txt --images_dim 28,28 data/mnist/sample_2.png foo

I think it would be a big help to new users if they could quickly try out networks and see results, so I hope this makes it in.

@shelhamer
Copy link
Member

Excellent to hear you are working on a beginner's guide to Caffe and holding a webinar. I hope that you can contribute back the documentation, examples, and instructions you've made as you've started to here.

Note that we do not accept PRs to master as a rule. However, since this change is slight and is part of an effort to explain Caffe I will review, merge to dev, then release in master. This way I can combine it with @longjon's improvements in #733 .

This was referenced Jul 28, 2014
@shelhamer
Copy link
Member

Sorry for the wait while I was traveling. I've included your improvements with minor changes in #816. The latest pycaffe will be released to master soon. Closing since this PR is against master.

Thanks for the nice label output and grayscale option!

@shelhamer shelhamer closed this Jul 29, 2014
@petewarden
Copy link
Author

Thanks Evan, looks good!

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.

None yet

3 participants