Test your DataSet with someone else's trained Caffemodel (only C + +)

Source: Internet
Author: User

Caffe program with a kitten picture (caffe/examples/images/cat.jpg), if we want to use a training good caffemodel to classify this picture, then how to do? If you do not use this kitten picture, for a different picture, how to do it. If you learn how to classify a kitten's image, then replace it with another picture, and the program is actually the same. The author looked for some of the zebra (zebra), ant (ant) and other JPG data to be tested.

To classify a picture, this Caffemodel is the best. So, whether we use C + + to classify, or use the Python interface to classify, we should prepare such three files:

1, Caffemodel documents.

You can either enter the address download directly in the browser or run the script file download. Download the address: Http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel

The file name is: Bvlc_reference_caffenet.caffemodel, the file size is about 230M, for the unification of the code, downloads this Caffemodel file to the Caffe root directory Models/bvlc_reference _caffenet/folder below. You can also run the script file for downloading:

  sudo./scripts/download_model_binary.py models/bvlc_reference_caffenet

2, mean value file.

With the Caffemodel file, you need the corresponding mean file, in the test phase, the test data need to subtract the mean value. This file is downloaded by our script and executed in the Caffe root directory:

  sudo sh./data/ilsvrc12/get_ilsvrc_aux.sh

After execution and download, the mean file is placed in the data/ilsvrc12/folder.

3, Synset_words.txt documents

When you invoke the script file to download the mean value, the file is also downloaded as well. It contains the names of 1000 classes.

In addition to the get_ilsvrc_aux.sh in the Data/ilsvrc12 folder, the new student became 8 files, as shown in the following figure:


The data is ready, we can start to categorize, here only C + + methods to test, the Python method for subsequent updates

In the Caffe root directory under the examples/cpp-classification/folder, there is a classification.cpp file, is used to classify. After compiling, put it under/build/examples/cpp_classification/, see below for details:


We'll run the command directly:

sudo./build/examples/cpp_classification/classification.bin \models/bvlc_reference_caffenet/deploy.prototxt Models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel Data/ilsvrc12/imagenet_mean.binaryproto data/ Ilsvrc12/synset_words.txt examples/images/cat.jpg

The command is very long and uses a lot of symbols to wrap the line. As you can see, the required files have deploy.prototxt Caffemodel mean.binaryproto synset_word.txt and JPG data

After the operation is successful, the output results are:

That is, 0.3134 of the probability of Tabby,tabby cat, 0.2380 of the probability of Tiger cat ...

I am on the internet to find a push JPG format data for testing (to be owned in the Synset_word.txt category), here to Ant,zebra as an example to demonstrate:

After downloading the image of the Ant (ant.jpg) and Zebra (zebra.jpg), place it in the Caffe/examples/images


We test the ants first:

sudo./build/examples/cpp_classification/classification.bin \models/bvlc_reference_caffenet/deploy.prototxt Models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel Data/ilsvrc12/imagenet_mean.binaryproto data/ Ilsvrc12/synset_words.txt examples/images/ant.jpg
After the operation is successful, the output results are:

That is, 0.5728 of the probability is Ant,emmet,pismire, 0.4023 of the probability of black widow,latrodectus mactans ...

Continue with the test zebra:

sudo./build/examples/cpp_classification/classification.bin \models/bvlc_reference_caffenet/deploy.prototxt Models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel Data/ilsvrc12/imagenet_mean.binaryproto data/ Ilsvrc12/synset_words.txt examples/images/zebra.jpg

After the operation is successful, the output results are:

That is, the probability of 0.9983 is zebra, and the probability of 0.0004 is park bench ...


                                                                                                                                                                                                                     -- ———— My Deep study notes, thank you for your reference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.