一、安装配置Ubuntu
1、查看系统版本
lsb_release -a # 查看当前系统版本
2、换源
注意:需要根据步骤1查出的代号对下方源中的代号进行替换
sudo vim /etc/apt/sources.list
# 阿里云镜像源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe
deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-security universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-security multiverse
sudo apt update
sudo apt upgrade
3、安装基础工具
sudo apt install g++ git unzip pkg-config make cmake
4、安装samba服务
(1)安装samba
sudo apt install samba
(2)打开smb.conf文件
sudo vim /etc/samba/smb.conf
在文件最后加入以下配置并保存,然后退出
[work]
comment = samba home directory
path = /home/lcat
public = yes
browseable = yes
public = yes
writeable = yes
read only = no
valid users = lcat
create mask = 0777
directory mask = 0777
#force user = nobody
#force group = nogroup
available = yes
(3)设置新的samba密码
sudo smbpasswd -a lcat
(4)重新启动samba服务
sudo service smbd restart
(5)查看Ubuntu的IP地址
ifconfig -a
(6)window访问samba共享文件(映射网络驱动器)
二、配置环境
(一)安装CUDA
1、下载
https://developer.nvidia.com/cuda-downloads
2、安装
执行以下命令,除了是否安装驱动选择no外,其余均选择yes,默认安装路径
sudo sh cuda_10.0.130_410.48_linux.run
sudo sh cuda_10.0.130.1_linux.run
3、配置环境变量
vim ~/.bashrc
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc
4、验证安装
nvcc -V
(二)安装cuDNN
1、下载
https://developer.nvidia.com/rdp/cudnn-archive
2、解压并进入该文件夹下,执行如下命令,进行相关文件的复制:
tar -xzvf cudnn-10.0-linux-x64-v7.6.5.32.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
3、打开终端,输入以下命令,查看cuDNN是否安装成功:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
(三)安装anaconda
1、下载
wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
2、安装
bash Anaconda3-5.2.0-Linux-x86_64.sh
一直Enter和yes,碰到安装Microsoft的VS code时选择No,结束安装
3、验证安装
conda -V
(四)安装opencv
1、下载
2、安装
unzip opencv-3.4.2.zip
cd opencv-3.4.2
sudo mkdir build
cd build
sudo cmake ../
sudo make -j8
sudo make install
3、验证安装
pkg-config --modversion opencv # 查看版本号
pkg-config --libs opencv # 查看libs库
三、安装依赖
sudo apt install protobuf-compiler libhdf5-serial-dev
sudo apt install libboost-all-dev libgflags-dev libgoogle-glog-dev libprotobuf-dev
sudo apt install libatlas-base-dev libleveldb-dev liblmdb-dev libsnappy-dev
四、编译caffe
1、拉取yolov5_caffe源码
git clone https://github.com/Wulingtian/yolov5_caffe.git
2、进入yolov5_caffe目录,配置环境变量
cd yolov5_caffe
export CPLUS_INCLUDE_PATH=/home/lcat/anaconda3/include/python3.6m
3、编译
make all -j8
4、测试yolov5推理
修改 yolov5_caffe/tools/caffe_yolov5s.cpp 参数
cd tools
vim caffe_yolov5s.cpp
INPUT_W 模型输入宽度
INPUT_H 模型输入高度
NUM_CLASS 模型有多少个类别
NMS_THRESH 做非极大值抑制的阈值
CONF_THRESH 类别置信度
prototxt_path caffe模型的prototxt路径
caffemodel_path caffe模型的caffemodel路径
pic_path 测试图片路径
修改完成返回yolov5_caffe目录,编译执行
make -j8
cd build
./tools/caffe_yolov5s
运行成功将输出平均推理时间,并保存预测图片到当前目录下
五、错误
错误1
make: protoc: Command not found
解决:
sudo apt install protobuf-compiler
错误2
src/caffe/layers/hdf5_data_layer.cu:10:10: fatal error: hdf5.h: No such file or directory
#include "hdf5.h"
解决:
sudo apt install libhdf5-serial-dev
错误3
./include/caffe/common.hpp:4:10: fatal error: boost/shared_ptr.hpp: No such file or directory
#include <boost/shared_ptr.hpp>
解决:
sudo apt install libboost-all-dev
错误4
./include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: No such file or directory
#include <gflags/gflags.h>
解决:
sudo apt install libgflags-dev
错误5
./include/caffe/common.hpp:6:10: fatal error: glog/logging.h: No such file or directory
#include <glog/logging.h>
解决:
sudo apt install libgoogle-glog-dev
错误6
.build_release/src/caffe/proto/caffe.pb.h:9:10: fatal error: google/protobuf/stubs/common.h: No such file or directory
#include <google/protobuf/stubs/common.h>
解决:
sudo apt install libprotobuf-dev
错误7
./include/caffe/util/mkl_alternate.hpp:14:10: fatal error: cblas.h: No such file or directory
#include <cblas.h>
解决:
sudo apt install libatlas-base-dev
错误8
examples/siamese/convert_mnist_siamese_data.cpp:20:10: fatal error: leveldb/db.h: No such file or directory
#include "leveldb/db.h"
解决:
sudo apt install libleveldb-dev
错误9
examples/mnist/convert_mnist_data.cpp:16:10: fatal error: lmdb.h: No such file or directory
#include <lmdb.h>
解决:
sudo apt install liblmdb-dev
错误10
/usr/bin/ld: cannot find -lsnappy
解决:
sudo apt install libsnappy-dev
错误11
F0105 14:44:33.180271 26467 pooling_layer.cu:212] Check failed: error == cudaSuccess (48 vs. 0) no kernel image is available for execution on the device
解决:根据安装的CUDA版本将 yolov5_caffe 中 Makefile.config 文件以下内容根据提示作出修改。本文将下列行:
CUDA_ARCH := -gencode arch=compute_61,code=compute_61
修改为:
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