以下为我参考JK Jung’s blog YOLOv3 on Jetson TX2在自己的TX2上测试yolo v3的过程。
$ sudo apt-get purge libopencv*
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ git clone https://github.com/pjreddie/darknet yolo3
$ cd yolo3
$ make
$ wget https://pjreddie.com/media/files/yolov3.weights
$ ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
格式: ./darknet detect .cfg 预训练权重 预测权重
以上出现问题,代码被kill,原因是TX2内存溢出,因此对Step2进行修改,开启GPU
$ vim Makefile
修改为:
GPU=1 #开启GPU
CUDNN=1 #
OPENCV=1 #开启Opencv
然后重新编译:
$ make
修改后仍溢出内存,发现是batch size太大了,不适合在TX2上跑,因此修改yolov3/cfg/yolov3.cfg
文件,将Training注释掉,改Testing的batch为1,即:
# Testing
batch=1
subdivisions=1
# Training
#batch=64
#subdivisions=16
重新编译成功!
成功!平均每张0.5s左右
1. 检测指定路径的图像
$ ./darknet detect cfg/yolov3.cfg yolov3.weights
会输出:Enter Image Path:
2.改变阈值:
By default, YOLO only displays objects detected with a confidence of .25
or higher. You can change this by passing the -thresh flag to the yolo command.
For example, to display all detection you can set the threshold to 0:
$ ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg -thresh 0
3. Tiny YOLOv3
在保证精度不损失太多的前提下,有个轻量级的网络—— yolov3-tiny.
$ wget https://pjreddie.com/media/files/yolov3-tiny.weights
$ ./darknet detect cfg/yolov3-tiny.cfg yolov3-tiny.weights data/dog.jpg
这是个轻量级的网络,因此耗时较短:0.034424s
4. 使用摄像头
$ ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
报错:
Couldn't connect to wecam. Resource temporarily unavaliable YOLO will display the current FPS and predicted classes as well as the image with bounding boxes drawn on top of it.
原因是OPENCV默认采用0号摄像头,TX2的0号摄像头是板子上自带的板上摄像头,而我们的usb摄像头是1号,故使用如下代码,解决了问题:
$ ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -c 1//使用1号摄像头