简介
本篇介绍一个使用 YOLOv8
目标检测算法和 DeepSort
目标跟踪算法的开源项目。
实操
git clone https://github.com/MuhammadMoinFaisal/YOLOv8-DeepSORT-Object-Tracking.git
cd YOLOv8-DeepSORT-Object-Tracking
# 创建一个全新的虚拟环境
conda create -n py38 python=3.8
# 激活虚拟环境
conda activate py38
# 安装依赖
pip install -e .
https://drive.google.com/drive/folders/1kna8eWGrSfzaR6DtNJ8_GchGgPMv3VC8,将整个文件夹下载,下来的是一个 zip
,将 zip
解压后, 文件夹放在目录 ultralytics/yolo/v8/detect
下
准备一段视频检测素材,放到目录 ultralytics/yolo/v8/detect
下,然后执行命令
# 使用yolov8l.pt模型,首次执行,会自动取下载,测试视频是10s.mp4,show参数表示处理过程中显示处理结果图像
python predict.py model=yolov8l.pt source="10s.mp4" show=True
FAQ
File "E:\Playground\YOLOv8-DeepSORT-Object-Tracking\ultralytics\yolo\v8\detect\deep_sort_pytorch\deep_sort\deep_sort.py", line 31, in update
detections = [Detection(bbox_tlwh[i], conf, features[i],oid) for i, (conf,oid) in enumerate(zip(confidences,oids)) if conf > self.min_confidence]
File "E:\Playground\YOLOv8-DeepSORT-Object-Tracking\ultralytics\yolo\v8\detect\deep_sort_pytorch\deep_sort\deep_sort.py", line 31, in <listcomp>
detections = [Detection(bbox_tlwh[i], conf, features[i],oid) for i, (conf,oid) in enumerate(zip(confidences,oids)) if conf > self.min_confidence]
File "E:\Playground\YOLOv8-DeepSORT-Object-Tracking\ultralytics\yolo\v8\detect\deep_sort_pytorch\deep_sort\sort\detection.py", line 30, in __init__
self.tlwh = np.asarray(tlwh, dtype=np.float)
File "D:\Tools\anaconda3\envs\py38\lib\site-packages\numpy\__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`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.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
这是由于 numpy
新版已经没有 float
属性了,降版本解决 pip install numpy==1.23.5
Traceback (most recent call last):
File "predict.py", line 253, in predict
predictor()
File "D:\Tools\anaconda3\envs\py38\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "e:\playground\yolov8-deepsort-object-tracking\ultralytics\yolo\engine\predictor.py", line 183, in __call__
preds = self.postprocess(preds, im, im0s)
File "predict.py", line 181, in postprocess
preds = ops.non_max_suppression(preds,
File "e:\playground\yolov8-deepsort-object-tracking\ultralytics\yolo\utils\ops.py", line 212, in non_max_suppression
i = torchvision.ops.nms(boxes, scores, iou_thres) # NMS
File "D:\Tools\anaconda3\envs\py38\lib\site-packages\torchvision\ops\boxes.py", line 41, in nms
return torch.ops.torchvision.nms(boxes, scores, iou_threshold)
File "D:\Tools\anaconda3\envs\py38\lib\site-packages\torch\_ops.py", line 755, in __call__
return self._op(*args, **(kwargs or {}))
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].
这个错误一般是由于 torch
和 torchvision
版本不匹配引起的,可以先卸载再重新安装。
pip uninstall torch torchvison
# 以安装gpu版本为例
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
下载
链接:https://pan.baidu.com/s/10cTn3_idG9ouUKyuisb5Kg
提取码:18tw