您的位置:首页 > 编程语言 > C语言/C++

CaffeNet C++ Classification 例子运行方法

2015-10-20 16:08 585 查看
/$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 labels

DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd $DIR

echo "Downloading..."

wget http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz 
echo "Unzipping..."

tar -xf caffe_ilsvrc12.tar.gz && rm -f caffe_ilsvrc12.tar.gz

echo "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++ 参数说明
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: