赞
踩
我所使用的deep sort不是别人改完的,而是deepsort论文作者nowjke的代码,在未完成这个文章之前我几乎没有在各大网站上看到过有关这个代码的任何教程,在学习期间也遇到了很多的很难,在学习目标追踪的道路上我认为需要这篇文章的解读,下面我将从一个刚接触过这篇文章的角度来过一下这个代码。
代码地址:GitHub - nwojke/deep_sort: Simple Online Realtime Tracking with a Deep Association Metric
一 创建环境
我使用的是anaconda
对于创建地址
conda create --name deepsort python=3.6
注意这里的python要小于3.7,因为后面的Tensorflow1.15只有在python<=3.7才可以下载。
创建完环境后,我们需要安装deepsort所需要的一些库
1.Numpy
pip install -U numpy==1.23.5
这个版本要对,否者后面会出现module ‘numpy‘ has no attribute ‘float‘的问题,主要是因为 np.float
从版本1.24
起被删除。
但是出现了错误,因为python的版本为3.6,所以装不了1.23.5,所以我们最后试一下1.19.5
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.19.5
这里使用了源地址
下面给出几个源地址,供以后使用
- 清华 https://pypi.tuna.tsinghua.edu.cn/simple
- 中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple
- 阿里云 http://mirrors.aliyun.com/pypi/simple/
- 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
- 豆瓣 http://pypi.douban.com/simple/
- Python https://pypi.python.org/simple
2.sklearn
pip install -U scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple
3.Opencv
对于opencv我的电脑不可以用pip直接下载,我使用先下载opencv的安装包在运行安装程序。
首先带开一个免费的网站:https://www.lfd.uci.edu/~gohlke/pythonlibs/
然后找到opencv这一模块,对应自己的python版本和系统的位数进行相应的下载。
我的python为3.6,系统型别为64位,我下载的名称为
将这个文件下载好放在对应的环境的scripts文件夹下,运行代码
pip3.6.exe install 文件路径
最后安装成功。
4.TensorFlow
因为需要用到generate_detections.py所以需要用到TensorFlow 1.5,下面进行TensorFlow的安装。
conda install Tensorflow==1.15.0
二 环境创建好后,开始进行目标追踪
1.直接追踪
这里我选择用pycharm,我们下载好代码后,打开总端,输入
python deep_sort_app.py --sequence_dir=D:/pycharm/deep_sort-master/deep_sort-master/MOT16/train/MOT16-09 --detection_file=D:/pycharm/deep_sort-master/deep_sort-master/resources/detections/MOT16_POI_train/MOT16-09.npy --output_file=D:/pycharm/deep_sort-master/deep_sort-master/data --min_confidence=0.3 --nn_budget=100 --display=True
就可以进行程序运行
2.训练自己的deepsort
对于自己的数据集,我们只需要训练detection就可以,这时我们需要这个
tools/generate_detections.py
所对应的程序为
- python tools/generate_detections.py --model=D:/pycharm/deep_sort-master/deep_sort-master/resources/networks/mars-small128.pb --mot_dir=D:/pycharm/deep_sort-master/deep_sort-master/MOT16/test --detection_dir=D:/pycharm/deep_sort-master/deep_sort-master/MOT16/test --output_dir=D:/pycharm/deep_sort-master/deep_sort-master/data
-
这里面每一个参数的的意义为
parser.add_argument( "--model", default="resources/networks/mars-small128.pb", help="Path to freezed inference graph protobuf.") parser.add_argument( "--mot_dir", help="Path to MOTChallenge directory (train or test)", required=True) parser.add_argument( "--detection_dir", help="Path to custom detections. Defaults to " "standard MOT detections Directory structure should be the default " "MOTChallenge structure: [sequence]/det/det.txt", default=None) parser.add_argument( "--output_dir", help="Output directory. Will be created if it does not" " exist.", default="detections")
这里面的 --detection_dir也可以不设,因为代码当中有
- if detection_dir is None:
- detection_dir = mot_dir
只有我们的--model参数需要提供,这里我使用的是作者提供的mars-small128.pb为预备训练的权重。--output_dir是我自己设定的生成文件夹,最后产生的预备训练权重就放在这里。
最后程序运行完就会在目标文件当中生成
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。