caffe_cpp_api
2015-11-15 00:31
323 查看
Classifying ImageNet: using the C++ API
Caffe, at its core, is written in C++. It is possible to use the C++API of Caffe to implement an image classification application similarto the Python code presented in one of the Notebook example. To lookat a more general-purpose example of the Caffe C++API, you shouldstudy the source code of the command line tool
caffein
tools/caffe.cpp.
Presentation
A simple C++ code is proposed inexamples/cpp_classification/classification.cpp. For the sake ofsimplicity, this example does not support oversampling of a singlesample nor batching of multiple independant samples. This example isnot trying to
reach the maximum possible classification throughput ona system, but special care was given to avoid unnecessarypessimization while keeping the code readable.
Compiling
The C++ example is built automatically when compiling Caffe. Tocompile Caffe you should follow the documented instructions. Theclassification example will be built asexamples/classification.binin your build directory.
Usage
To use the pre-trained CaffeNet model with the classification example,you need to download it from the "Model Zoo" using the followingscript:./scripts/download_model_binary.py models/bvlc_reference_caffenet
The ImageNet labels file (also called the synset file) is alsorequired in order to map a prediction to the name of the class:
./data/ilsvrc12/get_ilsvrc_aux.sh.
Using the files that were downloaded, we can classify the provided catimage (
examples/images/cat.jpg) using this command:
./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 output should look like this:
---------- Prediction for examples/images/cat.jpg ---------- 0.3134 - "n02123045 tabby, tabby cat" 0.2380 - "n02123159 tiger cat" 0.1235 - "n02124075 Egyptian cat" 0.1003 - "n02119022 red fox, Vulpes vulpes" 0.0715 - "n02127052 lynx, catamount"
Improving Performance
To further improve performance, you will need to leverage the GPUmore, here are some guidelines:Move the data on the GPU early and perform all preprocessingoperations there.
If you have many images to classify simultaneously, you should usebatching (independent images are classified in a single forward pass).
Use multiple classification threads to ensure the GPU is always fullyutilized and not waiting for an I/O blocked CPU thread.
相关文章推荐
- css3基础知识第五章实战训练
- [css]我要用css画幅画(三)
- JS Canvas动画之太极图
- KindEditor提交用jquery获取不到数据的解决方法
- 如何创建对象以及jQuery中创建对象的方式
- JQuery+EasyUI轻松实现步骤条效果
- WEB前端开发都应知道的jquery小技巧及jquery三个简写
- JavaScript和HTML DOM的区别与联系及Javascript和DOM的关系
- 深入浅析JavaScript中prototype和proto的关系
- javascript中window.open在原来的窗口中打开新的窗口(不同名)
- 详解JavaScript函数对象
- javascript 中的 delete及delete运算符
- 浅谈JavaScript中的对象及Promise对象的实现
- JavaScript中函数表达式和函数声明及函数声明与函数表达式的不同
- YouTube Video Download
- 配置设计
- 关于响应式的栅格应该怎样设置响应节点
- js 字符串操作
- JS base64 编码
- ReactiveCocoa入门教程——第二部分