参考链接:Caffe | Installation
安装依赖包
dnf install
dnf update
dnf install leveldb-devel snappy-devel opencv.aarch64 boost-devel hdf5-devel gflags-devel glog-devel lmdb-devel openblas.aarch64
dnf install git wget tar gcc-g++ unzip automake libtool autoconf
从源码编译安装protobuf
问题:
编译caffe需要用到protobuf,通过dnf install protobuf-devel可以获得3.19版本,但在后续编译caffe时会出现下图报错。报错原因:https://github.com/onnx/onnx/issues/2678,故而需要安装3.6~3.10版本的protobuf。
安装:
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout 3.9.x
./autogen.sh
./configure --prefix=/home/caffe/file/protobuf-install
make -j16
make install -j16
export PROTOBUF="/home/caffe/file/protobuf-install"
export PATH="$PROTOBUF/bin:$PATH"
export LD_LIBRARY_PATH="$PROTOBUF/lib:$LD_LIBRARY_PATH"
protoc --version
如果出现了版本号,则证明安装成功
安装caffe
git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config
vi Makefile.config
- 选择 cpu-only 模式: 将第8行CPU_ONLY := 1取消注释
- 选择 BLAS : 将第53行BLAS := atlas 改为BLAS := open
- 修改 INCLUDE 路径: 将第97行INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include 改为INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/opencv4 /usr/include/openblas /home/caffe/file/protobuf-install/include
- 修改 LIBRARY 路径: 将第98行LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib 改为LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /home/caffe/file/protobuf-install/lib
- 添加 LIBRARIES : 在第98行后面添加一行LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
在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
sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' src/caffe/test/test_io.cpp
sed -i 's/CV_LOAD_IMAGE_GRAYSCALE/cv::ImreadModes::IMREAD_GRAYSCALE/g' src/caffe/test/test_io.cpp
make all -j16
make test -j16
make runtest -j16
export CAFFE="/home/caffe/file/caffe"
export PATH="$CAFFE/build/tools:$PATH"
caffe --version
如果出现了版本号,则证明安装成功