yolov8_tracking复现

前言

检测与跟踪总是不分家的兄弟,今天也是选择了比较知名的网络对跟踪的效果进行复现

先看效果

yolov8_tracking复现_第1张图片

yolov8_tracking复现

clone仓库

仓库地址

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

命令行

git clone --recurse-submodules https://github.com/mikel-brostrom/yolov8_tracking.git

注意:yolov8_tracking仓库中有子仓库,所以需要使用到 --recurse-submodules

环境配置

conda create -n yolo-track python=3.8
cd yolov8_tracking
pip install -r requirements.txt

numpy的安装错误

错误提示

Using cached oauthlib-3.2.2-py3-none-any.whl (151 kB)
Building wheels for collected packages: lap
  Building wheel for lap (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [13 lines of output]
      Partial import of lap during the build process.
      Traceback (most recent call last):
        File "C:\Users\xinxi\AppData\Local\Temp\pip-install-dfe22xmq\lap_189420c6b93848c5baadcb9e681756d7\setup.py", line 127, in get_numpy_status
          import numpy
      ModuleNotFoundError: No module named 'numpy'
      Traceback (most recent call last):
        File "", line 2, in 
        File "", line 34, in 
        File "C:\Users\xinxi\AppData\Local\Temp\pip-install-dfe22xmq\lap_189420c6b93848c5baadcb9e681756d7\setup.py", line 236, in 
          setup_package()
        File "C:\Users\xinxi\AppData\Local\Temp\pip-install-dfe22xmq\lap_189420c6b93848c5baadcb9e681756d7\setup.py", line 220, in setup_package
          raise ImportError('lap requires numpy, '
      ImportError: lap requires numpy, please "pip install numpy".
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lap
  Running setup.py clean for lap
Failed to build lap
Installing collected packages: lap, executing, easydict, backcall, zipp, urllib3, typing-extensions, traitlets, tensorboard-data-server, sympy, soupsieve, smmap, six, rsa, PyYAML, PySocks, pyparsing, pygments, pyasn1-modules, psutil, protobuf, prompt-toolkit, Pillow, parso, packaging, oauthlib, numpy, networkx, MarkupSafe, kiwisolver, idna, grpcio, fonttools, filelock, decorator, cycler, colorama, charset-normalizer, cachetools, absl-py, werkzeug, tqdm, sentry-sdk, scipy, requests, python-dateutil, opencv-python, matplotlib-inline, jinja2, jedi, importlib-resources, importlib-metadata, google-auth, gitdb, contourpy, beautifulsoup4, asttokens, torch, stack-data, requests-oauthlib, pandas, matplotlib, markdown, gitpython, torchvision, thop, seaborn, ipython, google-auth-oauthlib, gdown, filterpy, tensorboard, ultralytics
  Running setup.py install for lap ... error
  error: subprocess-exited-with-error

  × Running setup.py install for lap did not run successfully.
  │ exit code: 1
  ╰─> [13 lines of output]
      Partial import of lap during the build process.
      Traceback (most recent call last):
        File "C:\Users\xinxi\AppData\Local\Temp\pip-install-dfe22xmq\lap_189420c6b93848c5baadcb9e681756d7\setup.py", line 127, in get_numpy_status
          import numpy
      ModuleNotFoundError: No module named 'numpy'
      Traceback (most recent call last):
        File "", line 2, in 
        File "", line 34, in 
        File "C:\Users\xinxi\AppData\Local\Temp\pip-install-dfe22xmq\lap_189420c6b93848c5baadcb9e681756d7\setup.py", line 236, in 
          setup_package()
        File "C:\Users\xinxi\AppData\Local\Temp\pip-install-dfe22xmq\lap_189420c6b93848c5baadcb9e681756d7\setup.py", line 220, in setup_package
          raise ImportError('lap requires numpy, '
      ImportError: lap requires numpy, please "pip install numpy".
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lap

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

解决方法

上面说的很清楚, ImportError: lap requires numpy, please “pip install numpy”
所以,手动先安装numpy

pip install numpy

然后继续

pip install -r requirements.txt

复现网络

使用摄像头进行复现

python track.py --source 0

权重文件错误

错误提示

track: yolo_weights=E:\1\yolo_track\yolov8_tracking\weights\yolov8s-seg.pt, reid_weights=E:\1\yolo_track\yolov8_tracking\weights\osnet_x0_25_msmt17.pt, tracking_method=deepocsort, tracking_config=trackers\deepocsort\configs\deepocsort.yaml, source=0, imgsz=[640, 640], conf_thres=0.5, iou_thres=0.5, max_det=1000, device=, show_vid=False, save_txt=False, save_conf=False, save_crop=False, save_trajectories=False, save_vid=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\track, name=exp, exist_ok=False, line_thickness=2, hide_labels=False, hide_conf=False, hide_class=False, half=False, dnn=False, vid_stride=1, retina_masks=False
Ultralytics YOLOv8.0.20  Python-3.8.16 torch-2.0.0+cpu CPU
Downloading https://github.com/ultralytics/assets/releases/download/v9.0/yolov8s-seg.pt to E:\1\yolo_track\yolov8_tracking\weights\yolov8s-seg.pt...
ERROR: HTTP Error 404: Not Found
Re-attempting https://github.com/ultralytics/assets/releases/download/v9.0/yolov8s-seg.pt to E:\1\yolo_track\yolov8_tracking\weights\yolov8s-seg.pt...
curl: (3) URL using bad/illegal format or missing URL
ERROR: Downloaded file 'E:\1\yolo_track\yolov8_tracking\weights\yolov8s-seg.pt' does not exist or size is < min_bytes=100000.0
E:\1\yolo_track\yolov8_tracking\weights\yolov8s-seg.pt missing, try downloading from https://github.com/ultralytics/assets/releases/v9.0

解决方法

这里提示的是文件不存在,发现了url实际上是不对的,真实的网址应该是https://github.com/ultralytics/assets/releases/
yolov8_tracking复现_第2张图片
手动下载这个文件,然后按照上面的错误提示中的路径,也就是放置在weights文件夹中

权重文件下载

  File "track.py", line 136, in run
    tracker = create_tracker(tracking_method, tracking_config, reid_weights, device, half)
  File "E:\1\yolo_track\yolov8_tracking\trackers\multi_tracker_zoo.py", line 69, in create_tracker
    botsort = OCSort(
  File "E:\1\yolo_track\yolov8_tracking\trackers\deepocsort\ocsort.py", line 360, in __init__
    self.embedder = ReIDDetectMultiBackend(weights=model_weights, device=device, fp16=fp16)
  File "E:\1\yolo_track\yolov8_tracking\trackers\strongsort\reid_multibackend.py", line 60, in __init__
    gdown.download(model_url, str(w), quiet=False)
  File "C:\Users\xinxi\miniconda3\envs\yolo-track\lib\site-packages\gdown\download.py", line 161, in download
    res = sess.get(url, stream=True, verify=verify)
  File "C:\Users\xinxi\miniconda3\envs\yolo-track\lib\site-packages\requests\sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
  File "C:\Users\xinxi\miniconda3\envs\yolo-track\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\xinxi\miniconda3\envs\yolo-track\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\xinxi\miniconda3\envs\yolo-track\lib\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='drive.google.com', port=443): Max retries exceeded with url: /uc?id=1Kkx2zW89jq_NETu4u42CFZTMVD5Hwm6e (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)')))

看起来又是文件的问题,看看错误的记录,请注意这句话

File "E:\1\yolo_track\yolov8_tracking\trackers\strongsort\reid_multibackend.py", line 60, in __init__
    gdown.download(model_url, str(w), quiet=False)

对应的源码就是

        if w.suffix == '.pt':
            model_url = get_model_url(w)
            if not file_exists(w) and model_url is not None:
                gdown.download(model_url, str(w), quiet=False)
            elif file_exists(w):
                pass
            else:
                print(f'No URL associated to the chosen StrongSORT weights ({w}). Choose between:')
                show_downloadeable_models()
                exit()

关注model_url变量,最终可以定位到reid_model_factory.py文件,对应的下载的路径为:
yolov8_tracking复现_第3张图片
我们手动将这个文件下载下来,下载下来的文件名为:osnet_x0_25_msmt17_combineall_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip_jitter.pth
但是需要注意

 gdown.download(model_url, str(w), quiet=False)

在这个语句中,download的第二个参数是重命名的文件名,把这个w打印出来是osnet_x0_25_msmt17.pt,所以,需要对上面的文件重命名为osnet_x0_25_msmt17.pt,放置在weights文件夹中.
现在的weights文件夹中,有了两个pt文件(但是实际上只是需要一个就OK了,没有太读代码,估计是传参的问题,因为有默认参数的存在,所以,导致依赖了两个pt文件)
yolov8_tracking复现_第4张图片
这两个文件都依赖于google下载,若是下载失败的话,可以评论或者是私信,我单独发送。

其他的测试

$ python track.py --source 0                               # webcam
                           img.jpg                         # image
                           vid.mp4                         # video
                           path/                           # directory
                           path/*.jpg                      # glob
                           'https://youtu.be/Zgi9g1ksQHc'  # YouTube
                           'rtsp://example.com/media.mp4'  # RTSP, RTMP, HTTP stream

你可能感兴趣的:(图像识别,YOLO,网络,python)