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”,使用以下命令:
安装yaml://yaml是什么
下载地址是 http://pyyaml.org/wiki/PyYAML
根据系统类型选择并下载,安装方法在页面下方。
安装好yaml之后运行命令,会在models/bvlc_reference_caffenet下下载文件 bvlc_reference_caffenet.caffemodle。
ImageNet的标签文件(也称为synset file,同义词集文件)也许要下载,用来对预测的类名做映射:
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
使用下载的文件,我们可以提供的小猫的图片进行分类,命令如下:
输出是这样的:
提高性能:
为了进一步提高性能,可以更多地利用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++ 参数说明
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.shsh文件内容:
#!/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++ 参数说明
相关文章推荐
- C++中delete和delete[]的区别
- 基本C++概念
- C语言中固定大小的数据类型的输入和输出
- kmp算法--c++ code
- Android C++中 sp<> wp<>知识
- 程序设计基石与实践系列之写一个C语言编译器
- 数组排序,并返回排序后的数组对应原数组的下标(c语言)
- 用rpm安装mysql5.6,C++连接mysql,/usr/lib -lmysqlclient找不到的解决办法
- 线性表的顺序存储结构(c语言源码实现)
- C++的private的属性或方法真的不能访问吗? no
- C++ string小结1
- =与==赋值与等于
- 用C++如何实现开放API接口服务器
- C语言标识符的3大属性
- C语言:Day5~Day6
- 《C++并发编程实战》读书笔记2---在线程间共享数据
- JNI 之二 :java & c/c++ 相互通信及调用
- C语言面向对象之继承、多态、可变参数、函数指针
- C++ 资源大全
- 如何修改MFC的图标