Create a new C + + project to call Caffe to recognize a picture

Source: Internet
Author: User

I've been running Caffe training data for a while ago. Before using the trained Caffemodel to classify the pictures are command-line instructions, and then think of their own new project to call Caffe, combined with classification code to classify the image. Internet access to a lot of information, the most detailed article is: http://blog.csdn.net/qq_14845119/article/details/52541622#reply.

First, step description

The main purpose of my writing today is to deepen my memory and understanding, mostly by referring to the content of the blogs given above. The following three steps are specifically divided into:
(1) Add input including directory, library directory, and links

(2) Copy the $\caffe\examples\cpp_classsification\classification.cpp to the new project and add

(3) Modify the Classification.cpp, add the corresponding deploy.prototxt,*.caffemodel,mean.binaryproto,synset_words.txt,*jpg, and classify.

Second, detailed steps 

 Now the above three steps are detailed:

1, because I only in the debug mode of the compilation, specific release mode contains directories, library directories and links, input add please refer to the above link.

The specific configuration and environment is: VS2013,WIN64,CPU environment

Include directory:

Library Directory:

Links, Input:

caffe.libcompute_image_mean.libconvert_imageset.libconvert_mnist_data.liblibcaffe.libopencv_ Highgui2410d.libopencv_imgproc2410d.libopencv_objdetect2410d.libopencv_core2410d.libopencv_ml2410d.liblibboost _date_time-vc120-mt-gd-1_59.liblibboost_filesystem-vc120-mt-gd-1_59.liblibboost_system- vc120-mt-gd-1_59.liblibglogd.libhdf5.libhdf5_cpp.libhdf5_f90cstub.libhdf5_fortran.libhdf5_hl.libhdf5_hl_ Cpp.libhdf5_hl_f90cstub.libhdf5_hl_fortran.libhdf5_ Tools.libszip.libzlib.libLevelDbD.liblmdbD.liblibprotobufD.liblibopenblas.dll.agflags_ Nothreadsd.libgflagsd.lib

PS: The nugetpackages root directory in the Glog,leveldb,protobuf directory under the Lib in the debug directory after the corresponding Lib plus d renamed, in order to distinguish with the release mode.

2, according to the above operation, has completed the inclusion of directories, library directories and links, the input added. The following changes are made to the copied classification.cpp:

Since the computer does not have a GPU, the first line of the program is added:

#define USE_OPENCV 1#define cpu_only 1

Make the following changes in the main () function:

The following can be compiled.

Iii. errors that will occur in the compilation

(1) Wrong form:

Workaround:

Project Properties page:c/c++-> command line, enter -d_scl_secure_no_warnings

(2) Wrong form:

Workaround: Place the opencv_ under the $\nugetpackages\opencv.2.4.10\build\native\bin\x64\v120\debug folder Copy the Core2410d.dll file to the new project $\testclassificationbycaffe\x64\debug folder.

If you encounter a missing. dll, go to Nugetpackages to search for the appropriate. dll file and copy it to the new project.

(3) Wrong form:

Workaround: Add a head.h file to the project and enter the following program:

#include"caffe/common.hpp"#include"caffe/layers/input_layer.hpp"#include"caffe/layers/inner_product_layer.hpp"#include"caffe/layers/dropout_layer.hpp"#include"caffe/layers/conv_layer.hpp"#include"caffe/layers/relu_layer.hpp"#include"caffe/layers/pooling_layer.hpp"#include"caffe/layers/lrn_layer.hpp"#include"caffe/layers/softmax_layer.hpp"  namespacecaffe{externInstantiate_class (Inputlayer); externInstantiate_class (Innerproductlayer); externInstantiate_class (Dropoutlayer); externInstantiate_class (Convolutionlayer);    Register_layer_class (convolution); externInstantiate_class (Relulayer);    Register_layer_class (ReLU); externInstantiate_class (Poolinglayer);    Register_layer_class (Pooling); externInstantiate_class (Lrnlayer);    Register_layer_class (LRN); externInstantiate_class (Softmaxlayer); Register_layer_class (Softmax);}

Then enter the # include "Head.h" in the classification.cpp.

However: At this point it is possible to make an error similar to the following:

This indicates that the layer convolution is re-registered, only the Register_layer_class (convolution) in the head.h is commented out, the same is true for the other layers.

All I have is a comment:

(4) Wrong form:

Workaround: Copy all 8 files under the $\nugetpackages\gflags.2.1.2.1\build\native\x64\v120\dynamic\lib directory to the project directory.

PS: This article is only used to make a summary and memory summary of yesterday's learning content, and added some of their own actual situation encountered some errors, hoping to bring some help to other people. Thanks again to the http://blog.csdn.net/qq_14845119/article/details/52541622#reply author for my guidance.

Create a new C + + project to call Caffe to recognize a picture

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.