Pages

Showing posts with label Caffe. Show all posts
Showing posts with label Caffe. Show all posts

2015/01/20

C++ Prediction Example With Caffe Deep Learning

In this example, we will using cifar10_quick_iter_5000.caffemodel as pre-trained model. And modified cifar10_quick_train_test.prototxt to get argmax for prediction.
Step1:Download the example from Github
Step2:Copy files to caffe master directory.
Copy files to your caffe master directory. keep the same directories and subdirectories.
 
    caffe-master/examples/images/cat10.png
    caffe-master/examples/images/dog10.png
    caffe-master/examples/images/truck10.png
    caffe-master/examples/prediction_example/file_list.txt
    caffe-master/examples/prediction_example/prediction_example.prototxt
    caffe-master/tools/prediction_example.cpp
 


Step3:Compile Example.
We assume you are ine the caffe master directory, just use make to compile our example.
    make
The caffe makefile will automatic find the new example and copy the result to build directory.
    caffe-master ikki$ ls ./build/tools/prediction_example*
    ./build/tools/prediction_example
    ./build/tools/prediction_example.bin
    ./build/tools/prediction_example.o
    ./build/tools/prediction_example.o.warnings.txt

Step4:Prediction
Just run the example.
    ./build/tools/prediction_example
    I0120 11:02:45.297869 2008834832 prediction_example.cpp:52] Result size: 3
    I0120 11:02:45.297899 2008834832 prediction_example.cpp:55] Blob size: 0
    I0120 11:02:45.297905 2008834832 prediction_example.cpp:58] -------------
    I0120 11:02:45.297910 2008834832 prediction_example.cpp:59]  prediction :  
    I0120 11:02:45.297919 2008834832 prediction_example.cpp:69] ------------------------------------------------------
    I0120 11:02:45.297924 2008834832 prediction_example.cpp:73] Pattern:0 class:5 Prob=2.69744e-06
    I0120 11:02:45.297940 2008834832 prediction_example.cpp:73] Pattern:1 class:3 Prob=4.0121e-05
    I0120 11:02:45.297948 2008834832 prediction_example.cpp:73] Pattern:2 class:9 Prob=0.00531694
    I0120 11:02:45.297956 2008834832 prediction_example.cpp:75] -------------

For run on GPU device.
    ./build/tools/prediction_example GPU 0

Here are the classes in the CIFAR-10 dataset:
    class:0 airplane
    class:1 automobile
    class:2 bird
    class:3 cat
    class:4 deer
    class:5 dog
    class:6 frog
    class:7 horse
    class:8 ship
    class:9 truck