一、Ubuntu16.04 GTX 1080Ti+CUDA9.0+GPU driver 390.77+cuDNN7
https://www.jianshu.com/p/a9dcf59bd896
1.1 CUDA与GPU Driver,cuDNN三者版本要匹配
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
- 安装CUDA 9.2 cuda-drivers 390.77,显示CUDA driver version is insufficient for CUDA runtime version
- 重新安装beta版 cuda-drivers 396.18 PASS,但是TensorFlow1.9不支持
1.2 重新安装CUDA9.0和GPU Driver390.77
$ sudo ./cuda_8.0.61_375.26_linux.run --no-opengl-libs
找了很久的原因,为什么Driver Not Selected。其实已经安装成功,可以直接下一步。
sudo nvidia-smi
二、安装 TensorFlow 1.9
https://www.tensorflow.org/install/install_linux
2.1 确定安装哪种 TensorFlow
$ sudo apt-get install cuda-command-line-tools
上述命令已自动实现
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}/usr/local/cuda/extras/CUPTI/lib64
为避免以后系统升级过程中出现 cuDNN 版本冲突,可将 cuDNN 版本保持为 7.0.5
$ sudo apt-mark hold libcudnn7 libcudnn7-dev
日后要允许进行升级,可以取消这一保持行为:
$ sudo apt-mark unhold libcudnn7 libcudnn7-dev
2.2 使用 Virtualenv 进行安装
(tensorflow)$ pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU
速度太慢,采用pypi 镜像使用帮助
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
(tensorflow)$ pip3 install https://pypi.tuna.tsinghua.edu.cn/simple some-package
请注意,每次使用 TensorFlow 时,您都必须激活 Virtualenv 环境。如果 Virtualenv 环境当前未处于活动状态,请调用以下命令之一:
$ source ~/targetDirectory/bin/activate # bash, sh, ksh, or zsh
$ source ~/tensorflow/bin/activate.csh # csh or tcsh
(tensorflow)$ deactivate
tensorflow–>targetDirectory
三、安装OpenCV3.4.0
https://blog.csdn.net/qq_36362060/article/details/80739573
pkg-config --modversion opencv #可以查看当前的opencv版本
3.1 OpenCV3.4.2 ./darknet 失败 卸载
https://stackoverflow.com/questions/51002010/opencv-assertion-failed-with-darknet
OPENCV3.4.2
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.2) /home/dir/opencv-3.4.2/modules/core/src/matrix_wrap.cpp:800: error: (-215:Assertion failed) (flags & FIXED_TYPE) != 0 in function 'type'
Darknet won’t compile with opencv 3.4.1. So i suggest downgrading
opencv to 3.4.0.
3.2 安装OpenCV3.4.0
1)安装依赖项
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
2)修改opencv编译配置文件
进入到opencv/cmake 目录下,找到OpenCVDetectCUDA.cmake文件并打开,定位到21行,修改set(HAVE_CUDA 1)为set(HAVE_CUDA 0)
3)安装opencv
cd build #进入到build文件夹
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. #开始编译
- 解决ippicv下载问题
https://blog.csdn.net/neilooo/article/details/78425559
- 去github下载对应的库
https://github.com/opencv/opencv_3rdparty/branches/all
ls -a #显示隐藏文件
make -j8
sudo make install -j8
四、安装yolov3
git clone https://github.com/pjreddie/darknet.git
https://pjreddie.com/darknet/install/#cuda
darknet的MakeFile配置,进入到下载下来的darknet文件夹下,打开Makefile,对如下几个地方进行修改:
CUDA=1
CUDNN=1
OPENCV=1
ARCH= -gencode arch=compute_61,code=[sm_61,compute_61]
4.1 Compiling With CUDA
GPU=1
./darknet -i 1 imagenet test cfg/alexnet.cfg alexnet.weights
./darknet -nogpu imagenet test cfg/alexnet.cfg alexnet.weights
4.2 Compiling With OpenCV
OPENCV=1
./darknet imtest data/eagle.jpg
make clean
make -j8
wget https://pjreddie.com/media/files/yolov3-tiny.weights #下载权重文件
./darknet detect cfg/yolov3-tiny.cfg yolov3-tiny.weights data/dog.jpg #使用下载的权重文件进行图片检测
四、Yolov3-tiny测试结果
对自行车和人的识别效果较好,狗的识别率有待提高。