安装caffe之前最好先装好opencv!
- ubuntu下opencv3.1.0安装:
安装需要的两个opencv文件在我的百度云中可以下载,百度云链接地址:链接:https://pan.baidu.com/s/1kUJl2zt 密码:iqft
具体安装教程见百度云中Linux下OpenCV安装PPT所示,讲解的很详细。编译成功之后可以用例子测试一下,PPT中也有具体讲解。
- 接下来就可以安装caffe(cpu-only):
与caffe官网的步骤一样。
ubuntu 18.04
(1). 下载好caffe,放到home下面
(2). 安装所需要的依赖
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
BLAS:
sudo apt-get install libatlas-base-dev
or install OpenBLAS by
sudo apt-get install libopenblas-dev
python: sudo apt-get install
python-dev
其它:
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
(3). 修改caffe配置文件:
$ cd caffe
$ cp Makefile.config.example Makefile.config
$ vim Makefile.config
- #CPU_ONLY := 1
+ CPU_ONLY := 1 注:cpu去掉#
$ vim Makefile
- opencv_core opencv_highgui opencv_imgproc
+ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
在位置((LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs))处添加opencv_imgcodecs
$ vim examples/cpp_classification/classification.cpp
+ #include <opencv2/imgproc/types_c.h>
+ #include <opencv2/objdetect/objdetect_c.h>
(4). 在caffe下创建自己的文件夹
cd caffe-master mkdir build
(5) 编译
cmake -D CMAKE_BUILD_TYPE=Release -D CPU_ONLY=ON ..
make all
sudo make install
make runtest
(6). 跑个demo:
$ ./data/cifar10/get_cifar10.sh #下载数据集
$ vim examples/cifar10/cifar10_quick_solver.prototxt
- solver_mode: GPU
+ solver_mode: CPU
$ ./examples/cifar10/create_cifar10.sh #生成caffe识别的数据模式
$ ./examples/cifar10/train_quick.sh #训练测试模型