CaffeNet C++ Classification 例子运行方法

来源:互联网 发布:数字移相算法 编辑:程序博客网 时间:2024/06/13 23:35

/$CAFFE_ROOT/examples/cpp_classification/readme.md

https://github.com/BVLC/caffe/blob/master/examples/cpp_classification/classification.cpp


编译:

这个C++的例子是在编译Caffe的时候自动编译的。

这个分类的例子被编译成build/examples/classification.bin


用法:

为了使用已经提前训练好的用于分类案例的CaffeNet模型,首先需要下载“Model Zoo”,使用以下命令:

./scripts/download_model_binary.py models/bvlc_reference_caffenet
可能灰遇到的问题是,在import yaml处报错。

安装yaml://yaml是什么

下载地址是 http://pyyaml.org/wiki/PyYAML

根据系统类型选择并下载,安装方法在页面下方。

安装好yaml之后运行命令,会在models/bvlc_reference_caffenet下下载文件 bvlc_reference_caffenet.caffemodle。


ImageNet的标签文件(也称为synset file,同义词集文件)也许要下载,用来对预测的类名做映射:

./data/ilsvrc12/get_ilsvrc_aux.sh
sh文件内容:

#!/usr/bin/env sh## N.B. This does not download the ilsvrcC12 data set, as it is gargantuan.# This script downloads the imagenet example auxiliary files including:# - the ilsvrc12 image mean, binaryproto# - synset ids and words# - Python pickle-format data of ImageNet graph structure and relative infogain# - the training splits with labelsDIR="$( cd "$(dirname "$0")" ; pwd -P )"cd $DIRecho "Downloading..."wget http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gzecho "Unzipping..."tar -xf caffe_ilsvrc12.tar.gz && rm -f caffe_ilsvrc12.tar.gzecho "Done."

caffe_ilsvrc12.tar.gz解压后包括一下几个文件:

det_synset_words.txt  

imagenet_mean.binaryproto 

test.txt

synsets.txt               

train.txt

imagenet.bet.pickle  

synset_words.txt          

val.txt


Using the files that were downloaded, we can classify the provided cat

使用下载的文件,我们可以提供的小猫的图片进行分类,命令如下:

./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

输出是这样的:
---------- 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"

提高性能:
为了进一步提高性能,可以更多地利用GPU,以下是指南:
* Move the data on the GPU early and perform all preprocessing
operations there.
* If you have many images to classify simultaneously, you should use
batching (independent images are classified in a single forward pass).
* Use multiple classification threads to ensure the GPU is always fully
utilized and not waiting for an I/O blocked CPU thread.


c++ 参数说明






0 0