0

I edited the code to a minimal example as per instructions of the first commentator Christoph Rackwitz.

I'm learning OpenCV, YOLO and DeepSORT with a code from a tutorial (https://github.com/computervisioneng/object-tracking-yolov8-deep-sort) but there seems to be a bug in the ultralytics library. The following minimal example

from ultralytics import YOLO
import cv2
import os
# set path for input video
video_path = os.path.join('/path_to/video_folder', 'test_video.mp4') 
# create OpenCV VideoCapture class instance for input video frame capturing
cap = cv2.VideoCapture(video_path)
# read first frame from test video
ret, frame = cap.read()
# set YOLO model
model = YOLO('yolov8n.pt')
# attempt to detect persons in the frame with YOLO, this causes error
results = model(frame)

produces error:

File "/home/jvkloc/Documents/TKT/Python/Sonify/minimal_example.py", line 13, in <module>
  results = model(frame)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/engine/model.py", line 111, in __call__
  return self.predict(source, stream, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
  return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/engine/model.py", line 250, in predict
  self.predictor.setup_model(model=self.model, verbose=is_cli)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/engine/predictor.py", line 295, in setup_model
  self.model = AutoBackend(model,
File "/usr/local/lib/python3.8/dist-packages/ultralytics/nn/autobackend.py", line 82, in __init__
  pt, jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle, triton = self._model_type(w)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/nn/autobackend.py", line 449, in _model_type
  if not is_url(p, check=False) and not isinstance(p, str):
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/utils/downloads.py", line 31, in is_url
  assert all([result.scheme, result.netloc]) # check if is url

builtins.AssertionError

The last line is related to a function from ultralytics/yolo/utils/downloads.py which is checking for urls. I do not understand why YOLO is doing that and why there should be an url in the code (if there should, I doubt it). Ultralytics library function mentioned in the last line of the error below. The line assert all([result.scheme, result.netloc]) # check if is url causes the error.

def is_url(url, check=True):
    """Check if string is URL and check if URL exists."""
    with contextlib.suppress(Exception):
        url = str(url)
        result = parse.urlparse(url)
        assert all([result.scheme, result.netloc])  # check if is url
        if check:
            with request.urlopen(url) as response:
                return response.getcode() == 200  # check if exists online
        return True
    return False

The idea is to go through my test video and apply YOLO object detection as well as DeepSORT tracking to it and produce an output video showing the tracking boxes and ids. But the code crashes with the error. Could someone with YOLO experience explain what is going on and fix this? Thank you!

jvkloc
  • 623
  • 1
  • 5
  • 13
  • 2
    submit a bug report to ultralytics. it's an issue internal to their library. please present a [mre]. all the opencv stuff (especially the writing) is beside the point. just load a picture to demonstrate the issue with the ultralytics library. – Christoph Rackwitz Jun 06 '23 at 20:11

0 Answers0