链接:https://pan.baidu.com/s/1Mv1VI1Wa5MUaHuKz9hlniQ
提取码:lmpk
复制这段内容后打开百度网盘手机App,操作更方便哦--来自百度网盘超级会员V4的分享
1.配置Anaconda+Pycharm
参考:https://www.cnblogs.com/shijingwen/p/14181885.html
在 Anconda Prompt 中,推荐创建新的虚拟环境
# 创建虚拟环境 xxx自己命名
conda create xxx
# 激活虚拟环境
# 安装依赖,这里使用的TensorFlow 2 GPU版
pip install -r requirement-gpu.txt
Tips:
1. 使用tensorflow-gpu版需配置GPU参考:help/pdf/Windows版YOLOv4目标检测实战:Windows系统上的软件安装,如果不使用tensorflow-gpu使用配置文件:config/requirement.txt
2. requirement-gpu.txt或requirement.txt配置文件放C:\Users\xxxx下
例如我的就把配置文件放在C:\Users\xxxx下(Ps:xxxx
是我的当前用户文件位置)
如果网络不好可以使用国内镜像, pip install xx -i http://xxx
国内的几个常用镜像地址:
豆瓣 : https://pypi.douban.com/simple
中国科学科技大学 : https://mirrors.ustc.edu.cn/pypi/web/simple/
清华大学 :https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/
3.预训练模型下载
本demo使用YOLOV4进行目标检测+DeepSort进行跟踪。
使用官方预训练好的目标检测模型,有80类物体可以检测。
yolov4.weights:https://drive.google.com/file/d/1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT/view?usp=sharing
yolov4-tiny.weights(小模型,运行更快但精度略低):https://drive.google.com/file/d/1ZVmrenfMJBqIWf5f5NAHNBxQw6DNJgvO/view?usp=sharing
Tips:
模型在: model 文件夹下
4.使用YOLOV4
# 将Darknet权重转换为Tensorflow模型
python save_model.py --model yolov4
# 在视频上运行yolov4深度排序对象跟踪器
python object_tracker.py --video ./data/video/test.mp4 --output ./outputs/demo.avi --model yolov4
# 在网络摄像头上运行yolov4深度排序对象跟踪器(将视频标志设置为0)
python object_tracker.py --video 0 --output ./outputs/webcam.avi --model yolov4
-
使用YOLOV4-Tiny
# 保存yolov4-tiny模型
python save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --model yolov4 --tiny
# 运行yolov4-tiny对象跟踪器
python object_tracker.py --weights ./checkpoints/yolov4-tiny-416 --model yolov4 --video ./data/video/test.mp4 --output ./outputs/tiny.avi --tiny
6.目标跟踪的范围
一般情况下,默认是coco数据集中所有的80个类。可以在
demo/object_tracker.py中更改如下第160和163行位置代码
Tips:
# 注释160,它读取cocoa .names里的跟踪类
160 #allowed_classes = list(class_names.values())
# 自己从80类中选需要的类,这里只允许car类
163 allowed_classes = ['car']
7.命令行参数参考
save_model.py:
--weights: path to weights file
(default: './data/yolov4.weights')
--output: path to output
(default: './checkpoints/yolov4-416')
--[no]tiny: yolov4 or yolov4-tiny
(default: 'False')
--input_size: define input size of export model
(default: 416)
--framework: what framework to use (tf, trt, tflite)
(default: tf)
--model: yolov3 or yolov4
(default: yolov4)
object_tracker.py:
--video: path to input video (use 0 for webcam)
(default: './data/video/test.mp4')
--output: path to output video (remember to set right codec for given format. e.g. XVID for .avi)
(default: None)
--output_format: codec used in VideoWriter when saving video to file
(default: 'XVID)
--[no]tiny: yolov4 or yolov4-tiny
(default: 'false')
--weights: path to weights file
(default: './checkpoints/yolov4-416')
--framework: what framework to use (tf, trt, tflite)
(default: tf)
--model: yolov3 or yolov4
(default: yolov4)
--size: resize images to
(default: 416)
--iou: iou threshold
(default: 0.45)
--score: confidence threshold
(default: 0.50)
--dont_show: dont show video output
(default: False)
--info: print detailed info about tracked objects
(default: False)
Tips: YOLOV4+DeepSort车流量检测网页显示