YOLOv4:目标检测(windows和Linux下Darknet 版本)实施

本文档介绍了如何在Windows和Linux环境下使用Darknet实现YOLOv4目标检测。包括从下载数据集、权重文件到验证性能、评估FPS的详细步骤,并提供了不同配置文件下的性能比较。此外,还提到了依赖项的需求,如CUDA、CuDNN、OpenCV等,以及如何在不同框架中实现YOLOv4。
摘要由CSDN通过智能技术生成

YOLOv4:目标检测(windows和Linux下Darknet 版本)实施

YOLOv4 - Neural Networks for Object Detection
(Windows and Linux version of Darknet )

YOLOv4论文链接:https://arxiv.org/abs/2004.10934

链接地址:https://github.com/AlexeyAB/darknet

darknet链接地址:http://pjreddie.com/darknet/

详细资料:http://pjreddie.com/darknet/yolo/

在AP和AP50下测试的性能比较

在这里插入图片描述

测试结果

在这里插入图片描述

在COCO数据集上如何评估YOLOv4的AP

Download and unzip
test-dev2017 dataset from MS COCO server: http://images.cocodataset.org/zips/test2017.zip

Download list of images for
Detection taks and replace the paths with yours: https://raw.githubusercontent.com/AlexeyAB/darknet/master/scripts/testdev2017.txt

Download yolov4.weights file: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT

Content of the file cfg/coco.data should be

classes= 80

train
= /trainvalno5k.txt

valid = /testdev2017.txt

names = data/coco.names

backup = backup

eval=coco

Create /results/ folder
near with ./darknet executable file

Run validation: ./darknet detector valid cfg/coco.data cfg/yolov4.cfg yolov4.weights

Rename the file /results/coco_results.json to detections_test-dev2017_yolov4_results.json and
compress it to detections_test-dev2017_yolov4_results.zip

Submit file detections_test-dev2017_yolov4_results.zip to the MS COCO evaluation server
for the test-dev2019 (bbox)

如何评估GPU上YOLOv4的帧率FPS

Compile Darknet with GPU=1 CUDNN=1 CUDNN_HALF=1 OPENCV=1 in the Makefile (or use the same settings with Cmake)

Download yolov4.weights file 245 MB: yolov4.weights (Google-drive mirror yolov4.weights )

Get any .avi/.mp4 video file
(preferably not more than 1920x1080 to avoid bottlenecks in CPU performance)

Run one of two commands and
look at the AVG FPS:

include
video_capturing + NMS + drawing_bboxes: ./darknet detector demo cfg/coco.data cfg/yolov4.cfg
yolov4.weights test.mp4 -dont_show -ext_output
exclude
video_capturing + NMS + drawing_bboxes: ./darknet detector demo cfg/coco.data cfg/yolov4.cfg
yolov4.weights test.mp4 -benchmark

预训练模型

There are weights-file for different cfg-files (trained for MS
COCO dataset):

FPS on RTX 2070 ® and Tesla V100 (V):

·
yolov4.cfg - 245 MB: yolov4.weights (Google-drive mirror yolov4.weights ) paper Yolo v4 just
change width= and height=parameters in yolov4.cfg file and use the same yolov4.weights file for all
cases:

width=608 height=608 in cfg: 65.7%
mAP@0.5 (43.5% AP@0.5:0.95) - 34® FPS / 62(V) FPS -
128.5 BFlops
width=512 height=512 in cfg: 64.9%
mAP@0.5 (43.0% AP@0.5:0.95) - 45® FPS / 83(V) FPS -
91.1 BFlops
width=416 height=416 in cfg: 62.8%
mAP@0.5 (41.2% AP@0.5:0.95) - 55® FPS / 96(V) FPS -
60.1 BFlops
width=320 height=320 in cfg: 60%
mAP@0.5 ( 38% AP@0.5:0.95) - 63® FPS / 123(V) FPS -
35.5 BFlops

· yolov3-tiny-prn.cfg - 33.1% mAP@0.5 - 370® FPS -
3.5 BFlops - 18.8 MB: yolov3-tiny-prn.weights

· enet-coco.cfg (EfficientNetB0-Yolov3) - 45.5%
mAP@0.5 - 55® FPS - 3.7 BFlops - 18.3 MB: enetb0-coco_final.weights

· yolov3-openimages.cfg - 247 MB - 18® FPS -
OpenImages dataset: yolov3-openimages.weights

CLICK ME - Yolo v3 modelsCLICK
ME - Yolo v2 models

Put it near compiled: darknet.exe

You
can get cfg-files by path: darknet/cfg/

依赖项需求

Windows or Linux
CMake >= 3.12: https://cmake.org/download/
CUDA 10.0: https://developer.nvidia.com/cuda-toolkit-archive (on
Linux do Post-installation Actions)
OpenCV >= 2.4:
use your preferred package manager (brew, apt), build from source using vcpkg or
download from OpenCV official site (on Windows set
system variable OpenCV_DIR = C:\opencv\build - where are the include and x64 folders image)
cuDNN >= 7.0 for CUDA 10.0 https://developer.nvidia.com/rdp/cudnn-archive (on Linux copy cudnn.h,libcudnn.so…
as desribed here https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installlinux-tar ,
on Windows copy cudnn.h,cudnn64_7.dll, cudnn64_7.lib as desribed here https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installwindows )
GPU with CC >= 3.0: https://en.wikipedia.org/wiki/CUDA#GPUs_supported
on
Linux GCC or Clang, on Windows MSVC
2015/2017/2019 https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community

Yolo v3 in other frameworks

TensorFlow: YOLOv4
on TensorFlow 2.0 / TFlite / Andriod: https://github.com/hunglc007/tensorflow-yolov4-tflite For
YOLOv3 - convert yolov3.weights/cfg files to yolov3.ckpt/pb/meta:
by using mystic123 project, and TensorFlow-lite
OpenCV-dnn the
fastest implementation for CPU (x86/ARM-Android), OpenCV can be compiled
with OpenVINO-backendfor running on (Myriad X
/ USB Neural Compute Stick / Arria FPGA), use yolov3.weights/cfg with: C++ example or Python example
Intel OpenVINO 2019 R1: (Myriad
X / USB Neural Compute Stick / Arria FPGA): read this manual
PyTorch > ONNX > CoreML >
iOS how to convert cfg/weights-files to
pt-file: ultralytics/yolov3 and iOS App
TensorRT YOLOv4
on TensorRT+tkDNN: https://github.com/ceccocats/tkDNN For
YOLOv3 (-70% faster inference): Yolo is natively supported in DeepStream 4.0 read PDF. wang-xinyu/tensorrtx implemented
yolov3-spp, yolov4, etc.
TVM -
compilation of deep learning models (Keras, MXNet, PyTorch, Tensorflow,
CoreML, DarkNet) into minimum deployable modules on diverse hardware
backends (CPUs, GPUs, FPGA, and specialized accelerators): https://tvm.ai/about
OpenDataCam -
It detects, tracks and counts moving objects by using Yolo: https://github.com/opendatacam/opendatacam#-hardware-pre-requisite
Netron -
Visualizer for neural networks: https://github.com/lutzroeder/netron

Datasets

MS
COCO: use ./scripts/get_coco_dataset.sh to
get labeled MS COCO detection dataset
OpenImages:
use python ./scripts/get_openimages_dataset.py for
labeling train detection dataset
Pascal
VOC: use python ./scripts/voc_label.py for
labeling Train/Test/Val detection datasets
ILSVRC2012
(ImageNet classification): use ./scripts/get_imagenet_train.sh (also imagenet_label.sh for labeling
valid set)
German/Belgium/Russian/LISA/MASTIF
Traffic Sign Datasets for Detection - use this parsers: https://github.com/angeligareta/Datasets2Darknet#detection-task
List
of other datasets: https://github.com/AlexeyAB/darknet/tree/master/scripts#datasets

怎样使用命令行

How to use on the command line

On
Linux use ./darknet instead of darknet.exe, like this:./darknet detector
test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights

On
Linux find executable file ./darknet in the root directory, while on Windows find it in the
directory \build\darknet\x64

Yolo
v4 COCO - image: darknet.exe detector test cfg/coco.data cfg/yolov4.cfg
yolov4.weights -thresh 0.25
Output coordinates of
objects: darknet.exe detector test
cfg/coco.data yolov4.cfg yolov4.weights -ext_output dog.jpg
Yolo
v4 COCO - video: darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg
yolov4.weights -ext_output test.mp4
Yolo
v4 COCO - WebCam 0: darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg
yolov4.weights -c 0
Yolo
v4 COCO for net-videocam -
Smart WebCam: darknet.exe detector demo
cfg/coco.data cfg/yolov4.cfg yolov4.weights
http://192.168.0.80:8080/video?dummy=param.mjpg
Yolo
v4 - save result videofile res.avi: darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg
yolov4.weights test.mp4 -out_filename res.avi
Yolo
v3 Tiny COCO - video: darknet.exe detector demo cfg/coco.data cfg/yolov3-tiny.cfg
yolov3-tiny.weights test.mp4
JSON and MJPEG server that
allows multiple connections from your soft or Web-browser ip-address:8070 and 8090: ./darknet detector demo ./cfg/coco.data ./cfg/yolov3.cfg
./yolov3.weights test50.mp4 -json_port 8070 -mjpeg_port 8090 -ext_output
Yolo
v3 Tiny on GPU #1: darknet.exe detector demo cfg/coco.data cfg/yolov3-tiny.cfg
yolov3-tiny.weights -i 1 test.mp4
Alternative
method Yolo v3 COCO - image: darknet.exe detect
cfg/yolov4.cfg yolov4.weights -i 0 -thresh 0.25
Train
on Amazon EC2, to see mAP &
Loss-chart using URL like: http://ec2-35-160-228-91.us-west-2.compute.amazonaws.com:8090 in
the Chrome/Firefox (Darknet should be compiled
with OpenCV): ./darknet detector
train cfg/coco.data yolov4.cfg yolov4.conv.137 -dont_show -mjpeg_port 8090
-map
186
MB Yolo9000 - image: darknet.exe
detector test cfg/combine9k.data cfg/yolo9000.cfg yolo9000.weights
Remeber
to put data/9k.tree and data/coco9k.map under the same folder of your app
if you use the cpp api to build an app
To
process a list of images data/train.txt and
save results of detection to result.json file
use: darknet.exe detector test
cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out
result.json < data/train.txt
To
process a list of images data/train.txt and
save results of detection to result.txt use:

 darknet.exe detector test cfg/coco.data cfg/yolov4.cfg
 yolov4.weights -dont_show -ext_output < data/train.txt > result.txt

Pseudo-lableing
- to process a list of images data/new_train.txt and
save results of detection in Yolo training format for each image as label <image_name>.txt (in this
way you can increase the amount of training data) use: darknet.exe detector test cfg/coco.data cfg/yolov4.cfg
yolov4.weights -thresh 0.25 -dont_show -save_labels <
data/new_train.txt
To
calculate anchors: darknet.exe
detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height
416
To
check accuracy mAP@IoU=50: darknet.exe detector
map data/obj.data yolo-obj.cfg backup\yolo-obj_7000.weights
To
check accuracy mAP@IoU=75: darknet.exe
detector map data/obj.data yolo-obj.cfg backup\yolo-obj_7000.weights
-iou_thresh 0.75

How to compile on Linux (using cmake)

The CMakeLists.txt will attempt to
find installed optional dependencies like CUDA, cudnn, ZED and build against
those. It will also create a shared object library file to use darknet for code development.

Open a bash terminal inside the cloned repository and launch:

./build.sh

How to compile on Linux (using make)

Just
do make in the darknet
directory. (You can try to compile and run it on Google Colab in cloud link (press «Open in Playground» button at the
top-left corner) and watch the video link )
Before make, you can set such options in the Makefile: link

GPU=1 to build with CUDA to
accelerate by using GPU (CUDA should be in /usr/local/cuda)
CUDNN=1 to build with cuDNN v5-v7 to
accelerate training by using GPU (cuDNN should be in /usr/local/cudnn)
CUDNN_HALF=1 to build for Tensor Cores
(on Titan V / Tesla V100 / DGX-2 and later) speedup Detection 3x, Training
2x
OPENCV=1 to build with OpenCV
4.x/3.x/2.4.x - allows to detect on video files and video streams from
network cameras or web-cams
DEBUG=1 to bould debug version of Yolo
OPENMP=1 to build with OpenMP support to
accelerate Yolo by using multi-core CPU
LIBSO=1 to build a library darknet.so and binary runable file uselib that uses this library. Or you
can try to run so LD_LIBRARY_PATH=./: L D L I B R A R

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值