最近由于服务器升级,对darknet重新编译。
新的环境为:Opencv3.4.12+CUDA10.2+Cudnn7.6.5+darknet
(1)Opencv3.4.12的安装
1.https://docs.opencv.org/3.4.12/d7/d9f/tutorial_linux_install.html
2.https://opencv.org/releases/
- 依赖包安装
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
- 下载
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
- 下载必备文件,防止因网速原因出错,主要有2个文件:IPPICV 和 face_landmark_model.dat,可参考博客https://blog.csdn.net/CSDN330/article/details/86747867
下载好文件后修改2个配置文件。
1. opencv/3rdparty/ippicv/ippicv.cmake
2. opencv_contrib-3.4.12/modules/face/CMakeLists.txt
将原来的网址修改问下载的文件保存路径,例如:
"file:///home/amax/Downloads/"
- build
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local .. \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/amax/Downloads/opencv_dis/opencv_contrib-3.4.12/modules . \
-D BUILD_EXAMPLES=ON ..
- install
make -j16
sudo make install
(2) CUDA10.2的安装
- 下载安装Nvidia驱动
快捷安装,打开软件和更新->附加驱动,自动搜索显卡驱动,选择其中一个驱动版本;点击应用更改等待安装完成,重启即可; - deb 安装cuda10.2
https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
- 配置CUDA环境变量
在.bashrc末尾添加两行环境变量
export PATH=$PATH:$/usr/local/cuda-10.2/bin #根据CUDA版本更换路径
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} #根据CUDA版本更换路径
保存退出,然后
source ~/.bashrc
- 重启电脑,并测试CUDA
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
(3) Cudnn7.6.5的安装
darknet不支持cudnn8以上,查看cudnn版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
下载解压,复制到cuda安装文件目录即可
sudo cp cuda/include/cudnn.h /usr/local/cuda/include 注意,解压后的文件夹名称为cuda ,将对应文件复制到 /usr/local中的cuda内
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
(4) darknet 编译
1.修改Makefile
2.修改代码src/image_opencv.cpp,因opencv升级修改修改源码 。
IplImage ipl = cvIplImage(m);
最后:
感谢浩哥老大提供技术支持!!!!!!