github地址:
https://github.com/mikel-brostrom/yolov8_tracking

到上面的github网站下载跟踪代码,该代码使用YOLOv8作为检测网络,不过YOLOv8的文件需要去下面的链接下载,然后替换掉跟踪代码中YOLOv8的空文件。
https://github.com/ultralytics/ultralytics

一、基本环境安装(X86,orin都可以运行)

见我的另外两偏文章:
orin上安装cuda pytorch gpu运行环境
使用Yolov8进行目标检测并训练自己的数据集
再根据

# pip install -r requirements.txt
ultralytics==8.0.20

# Base ----------------------------------------
gitpython
ipython  # interactive notebook
matplotlib>=3.2.2
numpy==1.23.1
opencv-python>=4.1.1
Pillow>=7.1.2
psutil  # system resources
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
thop>=0.1.1  # FLOPs computation
torch>=1.7.0  # see https://pytorch.org/get-started/locally (recommended)
torchvision>=0.8.1
tqdm>=4.64.0
# protobuf<=3.20.1  # https://github.com/ultralytics/yolov5/issues/8012

# Logging ---------------------------------------------------------------------
tensorboard>=2.4.1
# clearml>=1.2.0
# comet

# Plotting --------------------------------------------------------------------
pandas>=1.1.4
seaborn>=0.11.0

# StrongSORT ------------------------------------------------------------------
easydict

# torchreid -------------------------------------------------------------------
gdown

# ByteTrack -------------------------------------------------------------------
lap

# OCSORT ----------------------------------------------------------------------
filterpy

下载模型

yolov8需要的模型

这个我下载了yolov8s

跟踪需要的模型

ReID 模型

https://github.com/mikel-brostrom/yolov8_tracking/releases/download/v9.0/lmbn_n_cuhk03_d.pth
下载后改名 lmbn_n_cuhk03_d.pt,放到./weights

osnet模型

osnet_x1_0_imagenet.pth模型.下载地址:
https://drive.google.com/uc?id=1LaG1EJpHrxdAxKnSCJ_i0u-nbxSAeiFY
下载后,放到
~/.cache/torch/checkpoints

二、预测

运行跟踪命令

python track.py --source /home/xxx/AR0820_800W_H60_1.mp4 --tracking-method deepocsort --show-vid --yolo-weights ./yolov8/weights/yolov8s.pt 

其他命令具体见github

效果图

在这里插入图片描述

在这里插入图片描述

可能遇到的错误

1、ImportError: cannot import name ‘attempt_download’ from ‘ultralytics.yolo.utils.downloads’

ImportError: cannot import name 'attempt_download' from 'ultralytics.yolo.utils.downloads' (/home/xxxx/anaconda3/envs/pytorch_gpu/lib/python3.8/site-packages/ultralytics/yolo/utils/downloads.py)

yolov8环境版本问题

pip install ultralytics
pip install ultralytics==8.0.20

问题解决

requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘drive.google.com’, port=443): Max retries exceeded with url: /uc?id=1LaG1EJpHrxdAxKnSCJ_i0u-nbxSAeiFY (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x7f359975b940>: Failed to establish a new connection: [Errno 101] Network is unreachable’))

cached_file = os.path.join(model_dir, filename)
print("cached_file=",cached_file)
if not os.path.exists(cached_file):
    gdown.download(pretrained_urls[key], cached_file, quiet=False)

下载torch/checkpoints/osnet_x1_0_imagenet.pth文件的时候下载不下来报错。

将下载网址打印出来,找到有vpn的地方下载
https://drive.google.com/uc?id=1LaG1EJpHrxdAxKnSCJ_i0u-nbxSAeiFY

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐