天天看点

一切为了yolov3(Ubuntu版)—— yolov3 安装

1. 安装

参考官网:https://pjreddie.com/darknet/yolo/

下面重复列出官网步骤:

git clone https://github.com/pjreddie/darknet

cd darknet

make

wget https://pjreddie.com/media/files/yolov3.weights

./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg

           
一切为了yolov3(Ubuntu版)—— yolov3 安装

结果图:

一切为了yolov3(Ubuntu版)—— yolov3 安装

图片不是自动跳出来的,是在darknet文件夹中的一个predictions.jpg

一切为了yolov3(Ubuntu版)—— yolov3 安装

有这图你就成功了。其他详细信息参考上面官网。

下面详细搞下摄像头实时检测。

2.摄像头实时检测

参考官网Real-Time Detection on a Webcam部分:

一切为了yolov3(Ubuntu版)—— yolov3 安装

参考官网:https://pjreddie.com/darknet/install/#cuda

  • (1)按照官网步骤:
git clone https://github.com/pjreddie/darknet.git

cd darknet

make
           

你会看见:

一切为了yolov3(Ubuntu版)—— yolov3 安装

继续:

./darknet
           

看见:

一切为了yolov3(Ubuntu版)—— yolov3 安装
  • (2)编译CUDA和OpenCV

    参考我的其他blog:

    Linux安装CUDA11.0

    一切为了yolov3(Ubuntu版)——opencv3.4.0安装

  • 用CUDA编译

    装好之后,在CUDA根目录的Makefile文件中,修改GPU=1和OPENCV=1:

    一切为了yolov3(Ubuntu版)—— yolov3 安装
    改好后再:
make

./darknet -i 1 imagenet test cfg/alexnet.cfg alexnet.weights
           

我在make的时候出现了问题。

  • 问题1:nvcc not found

    解决方案:安装opencv-python和opencv-contrib-python(代码参看红框部分)

    一切为了yolov3(Ubuntu版)—— yolov3 安装
    一切为了yolov3(Ubuntu版)—— yolov3 安装
  • 问题2:nvcc找不到路径

    还没成功,找不到nvcc也可能是因为路径问题,需要修改.bashrc文件(在.bashrc中加入下面代码块里的东西)

#darknet
export PATH=/usr/local/cuda-11.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64:$LD_LIBRARY_PATH
           

成功操作指南:

一切为了yolov3(Ubuntu版)—— yolov3 安装
一切为了yolov3(Ubuntu版)—— yolov3 安装
  • 问题3:

    (以上步骤后,再次make,又报错)

    一切为了yolov3(Ubuntu版)—— yolov3 安装
    这是配置文件Makefile中配置的GPU架构和本机GPU型号不一致导致的
    一切为了yolov3(Ubuntu版)—— yolov3 安装
    我是这样改Makefile的:(下面的红框里面,author给了格式了,你挑一个匹配自己GPU的写上就行了)
    一切为了yolov3(Ubuntu版)—— yolov3 安装

问题3参考blog:https://blog.csdn.net/weixin_41813620/article/details/86063558

  • 官网介绍了两种方法:
  1. CUDA和GPU编译
./darknet -i 1 imagenet test cfg/alexnet.cfg alexnet.weights
           
  1. CUDA和CPU编译
./darknet -nogpu imagenet test cfg/alexnet.cfg alexnet.weights
           

CPU这里我出现了报错:imagenet

一切为了yolov3(Ubuntu版)—— yolov3 安装

解决办法:

./darknet -i 0 test ./data/horses.jpg cfg/alexnet.cfg alexnet.weights
           
一切为了yolov3(Ubuntu版)—— yolov3 安装
一切为了yolov3(Ubuntu版)—— yolov3 安装

出现以上多张小马图片,说明正确。

  • 用opencv编译
./darknet imtest data/eagle.jpg
           
一切为了yolov3(Ubuntu版)—— yolov3 安装
一切为了yolov3(Ubuntu版)—— yolov3 安装

如上图,darknet文件夹里面多了很多鹰的图。说明成功了。如果报错,检查下Makefile里面的OPENCV=1

继续阅读