ubuntu下编译caffe 并训练自定义数据集
caffe编译
这部分主要参见 https://www.linuxidc.com/Linux/2019-05/158422.htm
为了方便一并记下来,由于系统环境的不同网上的配置各式各样,我的系统环境:
ubuntu 18.04+CUDA 10.1+cudnn 7.5+python 3.6+opencv 4.0
- 安装依赖项
apt install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
apt install -y --no-install-recommends libboost-all-dev
apt install -y libatlas-base-dev
apt install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
2.下载caffe源码 https://github.com/BVLC/caffe 并修改Makefile.config.example 为 Makefile.config编辑配置文件。
- 关于opencv 4的修改,替换命令:
cd caffe
sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' src/caffe/layers/window_data_layer.cpp
sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' src/caffe/util/io.cpp
sed -i 's/CV_LOAD_IMAGE_GRAYSCALE/cv::ImreadModes::IMREAD_GRAYSCALE/g' src/caffe/util/io.cpp
- .config修改依次如下
USE_CUDNN := 1
OPENCV_VERSION := 3
CUDA_DIR := /usr/local/cuda-10.1
CUDA_ARCH := \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61