4

YOLOv8+DeepSort实现目标检测与追踪

 2 months ago
source link: https://xugaoxiang.com/2024/04/21/yolov8-deepsort/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

YOLOv8+DeepSort实现目标检测与追踪 - 迷途小书童的Note迷途小书童的Note

> 人工智能 > YOLOv8+DeepSort实现目标检测与追踪

本篇介绍一个使用 YOLOv8 目标检测算法和 DeepSort 目标跟踪算法的开源项目。



  1. git clone https://github.com/MuhammadMoinFaisal/YOLOv8-DeepSORT-Object-Tracking.git
  2. cd YOLOv8-DeepSORT-Object-Tracking
  3. # 创建一个全新的虚拟环境
  4. conda create -n py38 python=3.8
  5. # 激活虚拟环境
  6. conda activate py38
  7. # 安装依赖
  8. pip install -e .

https://drive.google.com/drive/folders/1kna8eWGrSfzaR6DtNJ8_GchGgPMv3VC8,将整个文件夹下载,下来的是一个 zip ,将 zip 解压后, 文件夹放在目录 ultralytics/yolo/v8/detect

YOLOv8 DeepSort

准备一段视频检测素材,放到目录 ultralytics/yolo/v8/detect 下,然后执行命令



  1. # 使用yolov8l.pt模型,首次执行,会自动取下载,测试视频是10s.mp4,show参数表示处理过程中显示处理结果图像
  2. python predict.py model=yolov8l.pt source="10s.mp4" show=True
YOLOv8 DeepSort


  1. File "E:\Playground\YOLOv8-DeepSORT-Object-Tracking\ultralytics\yolo\v8\detect\deep_sort_pytorch\deep_sort\deep_sort.py", line 31, in update
  2. detections = [Detection(bbox_tlwh[i], conf, features[i],oid) for i, (conf,oid) in enumerate(zip(confidences,oids)) if conf > self.min_confidence]
  3. File "E:\Playground\YOLOv8-DeepSORT-Object-Tracking\ultralytics\yolo\v8\detect\deep_sort_pytorch\deep_sort\deep_sort.py", line 31, in <listcomp>
  4. detections = [Detection(bbox_tlwh[i], conf, features[i],oid) for i, (conf,oid) in enumerate(zip(confidences,oids)) if conf > self.min_confidence]
  5. File "E:\Playground\YOLOv8-DeepSORT-Object-Tracking\ultralytics\yolo\v8\detect\deep_sort_pytorch\deep_sort\sort\detection.py", line 30, in __init__
  6. self.tlwh = np.asarray(tlwh, dtype=np.float)
  7. File "D:\Tools\anaconda3\envs\py38\lib\site-packages\numpy\__init__.py", line 305, in __getattr__
  8. raise AttributeError(__former_attrs__[attr])
  9. AttributeError: module 'numpy' has no attribute 'float'.
  10. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  11. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
  12. https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  13. Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

这是由于 numpy 新版已经没有 float 属性了,降版本解决 pip install numpy==1.23.5



  1. Traceback (most recent call last):
  2. File "predict.py", line 253, in predict
  3. predictor()
  4. File "D:\Tools\anaconda3\envs\py38\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
  5. return func(*args, **kwargs)
  6. File "e:\playground\yolov8-deepsort-object-tracking\ultralytics\yolo\engine\predictor.py", line 183, in __call__
  7. preds = self.postprocess(preds, im, im0s)
  8. File "predict.py", line 181, in postprocess
  9. preds = ops.non_max_suppression(preds,
  10. File "e:\playground\yolov8-deepsort-object-tracking\ultralytics\yolo\utils\ops.py", line 212, in non_max_suppression
  11. i = torchvision.ops.nms(boxes, scores, iou_thres) # NMS
  12. File "D:\Tools\anaconda3\envs\py38\lib\site-packages\torchvision\ops\boxes.py", line 41, in nms
  13. return torch.ops.torchvision.nms(boxes, scores, iou_threshold)
  14. File "D:\Tools\anaconda3\envs\py38\lib\site-packages\torch\_ops.py", line 755, in __call__
  15. return self._op(*args, **(kwargs or {}))
  16. NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'torchvision::nms' is only available for these backends: [CPU, Meta, QuantizedCPU, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradMPS, AutogradXPU, AutogradHPU, AutogradLazy, AutogradMeta, Tracer, AutocastCPU, AutocastCUDA, FuncTorchBatched, BatchedNestedTensor, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].

这个错误一般是由于 torchtorchvision 版本不匹配引起的,可以先卸载再重新安装。



  1. pip uninstall torch torchvison
  2. # 以安装gpu版本为例
  3. pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

链接:https://pan.baidu.com/s/10cTn3_idG9ouUKyuisb5Kg
提取码:18tw


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK