本文引用、參考自: https://github.com/weiliu89/caffe/tree/ssd
https://blog.csdn.net/mhsszm/article/details/90238119
https://blog.csdn.net/beckhans/article/details/89393280
做個配置記錄
1.系統環境檢測,默認nano都裝好了的
# 檢查CUDA
nvcc -V
# 檢查opencv
pkg-config opencv --modversion
# 檢查cuDNN
cd /usr/src/cudnn_samples_v7/mnistCUDNN #進入例子目錄
sudo make #編譯一下例子
sudo chmod a+x mnistCUDNN # 爲可執行文件添加執行權限
./mnistCUDNN # 執行
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
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install git build-essential
這裏沒有安裝cmake,因爲版本比較老,不支持cuda10,所以要去官網下載最新版編譯
3.cmake編譯安裝
(1)如果有安裝了cmake的,卸載
sudo apt-get remove cmake -y
(2)下載cmake3.15,找最新版源碼下載就行了
(3)編譯安裝
tar -xzvf cmake3.15***
cd cmake3.15***
sudo ./bootstrap
sudo make -j4
sudo make install
(4)查看cmake安裝成功與否
cmake --version
就會出來版本號,若提示找不到cmake則做如下處理:
whereis cmake
result :
cmake: /usr/lib/aarch64-linux-gnu/cmake /usr/lib/cmake /usr/local/bin/cmake /usr/share/cmake
vim ~/.bashrc
添加:
export PATH=:/usr/local/bin/cmake:$PATH
source ~/.bashrc
4.caffe 或 caffe-ssd安裝準備
(1)創建Swap交換空間,這裏新建4G
# 先禁用以前的
sudo swapoff /swapfile
# 修改swap 空間的大小爲4G
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
# 設置文件爲“swap file”類型
sudo mkswap /swapfile
# 啓用swapfile
sudo swapon /swapfile
# 在/etc/fstab中添加下面代碼,將swap空間永久保留,不執行這句重新啓動後swap空間被釋放
/swapfile swap swap defaults 0 0
(2)下載caffe或caffe-ssd
如果安裝caffe的話
git clone https://github.com/BVLC/caffe.git
cd caffe
如果安裝caffe-ssd的話,這裏改下名好區分
git clone https://github.com/weiliu89/caffe.git
mv caffe caffe_ssd
cd caffe_ssd
git checkout ssd
這裏開始caffe和caffe-ssd都一樣
sudo cp Makefile.config.example Makefile.config
sudo vim Makefile.config
編輯Makefile.config文件
# 將下面三句前面的註釋符號去掉
USE_CUDNN := 1
OPENCV_VERSION := 3
WITH_PYTHON_LAYER := 1
# 將下面這段話中20和21那部分刪掉,刪掉後如下
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,code=sm_61 \
-gencode arch=compute_61,code=compute_61
# 修改路徑,註釋掉原來的,換成新的
#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu/hdf5/serial
編輯Makefile文件
sudo vim Makefile
# 這一句在425行
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
#如果是caffe的話
# 這一句在181行
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
#如果是caffe-ssd的話
# 這一句在181行
LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial
5.編譯安裝caffe或caffe-ssd
mkdir build && cd build
cmake ..
make -j4
make install
make pycaffe #建立python接口
make runtest #測試,此步不是必要的,可以選做
6.環境變量配置,和測試
sudo vim ~/.bashrc
#在最後添加
#我的是
export PYTHONPATH=/home/admin/ssd_caffe/python:$PYTHONPATH
#相應改成
export PYTHONPATH=/home/用戶名/caffe的根目錄,就是下載時那個目錄/python:$PYTHONPATH
#改好後 :wq 保存退出
#命令行輸入
source ~/.bashrc
#環境變量立馬生效
#測試 命令行
python
import caffe
如沒有任何輸出 ,成功
但一般會卻少庫,安裝就好了