识别算法CentOS部署手册
这是一个目标检测、人脸识别项目的部署手册,包含了一些开发环境的配置方法,相关包已经上传到了我的资源。
环境需求
- CentOS 7
- NVIDIA Driver
- CMake 3.17
- CUDA 10.0
- CUDNN 7.6.5
- FFmpeg
- OpenCV 4.2.0
- DarkNet
- SeetaFace6
安装CentOS
- 正常安装CentOS 7
安装NVIDIA显卡驱动
- 驱动下载
- https://www.nvidia.cn/Download/index.aspx?lang=cn#
- 上述地址下载所需显卡驱动
- 环境准备
- 环境依赖
- 安装kernel-devel
sudo yum install kernel-devel
- 检查内核版本和源码版本,保证一致
ls /boot | grep vmlinuz
rpm -aq | grep kernel-devel
- 安装gcc
sudo yum install gcc
- 安装make
sudo yum install make
- 禁用nouveau
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
- 在 blacklist-nouveau.conf 中插入如下两行
blacklist nouveau
options nouveau modeset=0
- 重建initramfs image
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
dracut /boot/initramfs-$(uname -r).img $(uname -r)
reboot
- 验证是否生效,无输出则生效
lsmod | grep nouveau
- 修改运行级别为文本模式
sudo systemctl set-default multi-user.target
reboot
- 安装kernel-devel
- 环境依赖
- 安装
- 运行安装程序
sudo sh NVIDIA-XXXX-XXXX.run
- install nvidia’s 32-bit
- no
- 其他选项
- yes
- 验证安装
nvidia-smi
- 运行安装程序
安装CMake 3.17.5
- 下载
- https://cmake.org/download/
- 上述地址下载 CMake 3.17.5
- 安装
- 解压压缩包
- 配置环境变量
vim ~/.bashrc
- 在bashrc最后添加
export PATH=XXXXXXX/bin:$PATH
- XXXXXXX 为CMake解压后的路径
source .bashrc
- 验证
cmake --version
cmake-gui --version
安装CUDA和CUDNN
- 下载
- https://developer.nvidia.com/cuda-10.0-download-archive
- 上述地址下载cuda10.0及其补丁包
- https://developer.nvidia.com/cudnn
- 上述地址下载对应cudnn
- 安装CUDA
sudo ./cuda_10.0.130_410.48_linux.run
- Do you accept the previously read EULA?
- accept
- Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
- no
- Install the CUDA 10.0 Toolkit?
- yes
- Enter Toolkit Location [ default is /usr/local/cuda-10.0 ]:
- 回车确定选择默认位置
- Do you want to install a symbolic link at /usr/local/cuda?
- yes
- Install the CUDA 10.0 Samples?
- yes
- Enter CUDA Samples Location [ default is /home/yfzx ]:
- 回车确定选择默认位置
- Do you accept the previously read EULA?
sudo ./cuda_10.0.130.1_linux.run
- Do you accept the previously read EULA?
- accept
- Enter CUDA Toolkit installation directory [ default is /usr/local/cuda-10.0 ]:
- 回车确定选择默认位置
- Do you accept the previously read EULA?
- 配置环境变量
vim ~/.bashrc
- 在bashrc后面添加
export PATH=/usr/local/cuda-10.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
source .bashrc
- 验证
nvcc -V
- 安装CUDNN
- 解压压缩包
cd cudnn-XXXX/cuda/
sudo cp include/cudnn.h /usr/local/cuda-10.0/include/
sudo cp lib64/libcudnn* /usr/local/cuda-10.0/lib64/
sudo chmod a+r /usr/local/cuda-10.0/include/cudnn.h
sudo chmod a+r /usr/local/cuda-10.0/lib64/libcudnn*
- 验证
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
- 修改cudnn的软连接
cd /usr/local/cuda-10.0/lib64/
sudo rm libcudnn.so.7
sudo ln -s libcudnn.so.7.6.5 libcudnn.so.7
编译安装OpenCV4.2.0
- 根据OpenCV4.2.0压缩包完成以下操作
- 环境依赖
sudo yum -y install epel-release
wget https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm 2
wget https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm 1
rpm -ivh *.rpm
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
sudo yum install ffmpeg
sudo yum install ffmpeg-devel
sudo yum install gtk2
sudo yum install gtk2-devel
sudo yum install libdc1394-devel
sudo yum install libv4l-devel
sudo yum install gstreamer-plugins-base-devel
sudo yum install jsoncpp
sudo yum install jsoncpp-devel
- 验证FFmpeg安装成功
ffmpeg
- 解压压缩包
cd /opencv4.2.0/opencv4.2.0
mkdir build
cd build
cmake ..
或者cmake-gui ..
CMAKE_INSTALL_PREFIX=/usr/local/opencv4.2
OPENCV_EXTRA_MODULES_PATH=XXXX/opencv_contrib-4.2.0/modules
opencv_contrib-4.2.0文件在opencv4.2压缩包内,填入路径即可OPENCV_GENERATE_PKGCONFIG=YES
WITH_CUDA=ON
OPENCV_DNN_CUDA=ON
OPENCV_ENABLE_NONFREE=ON
CUDA_ARCH_BIN=6.0 6.1 7.0 7.5
- 确保cmake信息中Video I/O下FFMPEG信息全为YES
- 上一步的完整命令 XXXXXX替换成安装路径即可
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.2 -D OPENCV_EXTRA_MODULES_PATH=XXXXXX/opencv4.2.0/opencv_contrib-4.2.0/modules -D OPENCV_GENERATE_PKGCONFIG=YES -D WITH_CUDA=ON -D OPENCV_DNN_CUDA=ON -D OPENCV_ENABLE_NONFREE=ON -D CUDA_ARCH_BIN=6.0 6.1 7.0 7.5 ..
make
sudo make install
编译安装DarkNet
- 下载
- https://github.com/AlexeyAB/darknet
- 上述地址下载DarkNet
- 安装
- 解压压缩包
- 修改makefile文件
- GPU=1
- CUDNN=1
- OPENCV=1
- LIBSO=1
- 修改 LDFLAGS中CUDA和CUDNN路径为本机安装路径
- 修改 COMMON中CUDA路径为本机安装路径
cd darknet
mkdir build
cd build
cmake ..
make
make install
- 将动态库和头文件移动到/usr/local/下
cd /usr/local
sudo mkdir darknet
cd darknet
sudo mkdir lib
- 将编译后的darknet文件夹中的libdrak.so移动到/usr/local/darknet/lib/下
- 将编译后的darknet文件夹中的include文件夹移动到/usr/local/darknet/下
安装SeetaFace6
- 下载
- https://github.com/yisampi/SeetaFace6
- 上述地址下载Ubuntu系统的压缩包
- 安装
- 解压压缩包
- 将解压后的文件夹重命名为seetaface6
- 将seetaface6文件夹移动到/usr/local/下
动态库配置
cd /etc/ld.so.conf.d
sudo vim cuda.conf
- 添加
/usr/local/cuda-10.0/lib64
- 添加
sudo vim darknet.conf
- 添加
/usr/local/darknet/lib
- 添加
sudo vim opencv4.conf
- 添加
/usr/local/opencv4.2/lib64
- 添加
sudo vim seetaface6.conf
- 添加
/usr/local/seetaface6/lib64
- 添加
sudo ldconfig