mikel-brostrom/boxmot

DeepOCSORT example fails with 'AttributeError: 'str' object has no attribute 'type''

Closed this issue Β· 9 comments

Search before asking

  • I have searched the Yolo Tracking issues and found no similar bug report.

Question

Hi!

I am trying the DeepOCSORT tracking example in readme. I installed boxmot using pip install boxmot. The version it shows is 10.0.52

import cv2
import numpy as np
from pathlib import Path

from boxmot import DeepOCSORT


tracker = DeepOCSORT(
    model_weights=Path('osnet_x0_25_msmt17.pt'), # which ReID model to use
    device='cuda:0',
    fp16=False,
)

vid = cv2.VideoCapture(0)

while True:
    ret, im = vid.read()

    # substitute by your object detector, output has to be N X (x, y, x, y, conf, cls)
    dets = np.array([[144, 212, 578, 480, 0.82, 0],
                    [425, 281, 576, 472, 0.56, 65]])

    tracker.update(dets, im) # --> M X (x, y, x, y, id, conf, cls, ind)
    tracker.plot_results(im, show_trajectories=True)

    # break on pressing q or space
    cv2.imshow('BoxMOT detection', im)     
    key = cv2.waitKey(1) & 0xFF
    if key == ord(' ') or key == ord('q'):
        break

vid.release()
cv2.destroyAllWindows()

It fails with the below error

  Traceback (most recent call last):
    File "/home/dt/Projects/Work/greenox/hwt/trackingfordelta/anycamyolov8_moxbotsort.py", line 32, in <module>
      tracker = DeepOCSORT(
    File "/home/dt/Projects/Work/greenox/ultralytics/venv/lib/python3.10/site-packages/boxmot/trackers/deepocsort/deep_ocsort.py", line 350, in __init__
      self.model = rab.get_backend()
    File "/home/dt/Projects/Work/greenox/ultralytics/venv/lib/python3.10/site-packages/boxmot/appearance/reid_auto_backend.py", line 72, in get_backend
      return backend_class(self.weights, self.device, self.half)
    File "/home/dt/Projects/Work/greenox/ultralytics/venv/lib/python3.10/site-packages/boxmot/appearance/backends/pytorch_backend.py", line 13, in __init__
      super().__init__(weights, device, half)
    File "/home/dt/Projects/Work/greenox/ultralytics/venv/lib/python3.10/site-packages/boxmot/appearance/backends/base_backend.py", line 18, in __init__
      self.cuda = torch.cuda.is_available() and self.device.type != "cpu"
  AttributeError: 'str' object has no attribute 'type'

I think the readme needs to be changed. it should be device=torch.device("cpu")

torch.device("cpu") or device=torch.device("cuda:0")

the solution of @thptai would be the bestπŸ‘πŸ‘

another way, you(@programmeddeath1 ) can modify the line 18 of boxmot/appearance/backends/base_backend.py
from
self.cuda = torch.cuda.is_available() and self.device.type != "cpu"
to
self.cuda = torch.cuda.is_available() and self.device != "cpu"

but I recommend the solution of @thptai , that modify "code of Custom tracking examples",
because mine could be affect other.

@thptai maybe you could be a contributor for this project,
if you modify the README with your solution and make a pull request!!

like below way
(e.g.)

import cv2
**import torch**
import numpy as np
from pathlib import Path

from boxmot import DeepOCSORT


tracker = DeepOCSORT(
    model_weights=Path('osnet_x0_25_msmt17.pt'), # which ReID model to use
    **device=torch.device('cuda:0'),**
    fp16=False,
)

vid = cv2.VideoCapture(0)
...

Thank you for sharing your idea
hope you have a peaceful dayπŸ˜†

I will fix this at tracker level instead. Thx for pointing this bug out!

Should have been fixed. Let me know @J4BEZ , @thptai, @programmeddeath1 if it works now

@mikel-brostrom Sorry for late reply and very appreciate for your hard workπŸ™‡β€β™‚οΈ

In my case, I caught an error like below.

...
    with open(ROOT / "pyproject.toml", "r") as file:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\J4BEZ\\Anaconda\\envs\\sample\\Lib\\site-packages\\pyproject.toml'

when I download poetry.lock and pyproject.toml to the root of my env where I install boxmot
(in this case, under D:\\J4BEZ\\Anaconda\\envs\\sample\\Lib\\site-packages\\)

and run the sample code ,
it works perfectly as we expected!

@mikel-brostrom

In my case, I install boxmot not git clone https://github.com/mikel-brostrom/yolo_tracking.git but pip install -U boxmot.
so the poetry.lock and pyproject.toml which exist outside of 'boxmot' folder have left when I install boxmot

if we copy poetry.lock and pyproject.toml to boxmot folder and change the path in torch_utils.py line 66

    with open(ROOT / "pyproject.toml", "r") as file:

We would be able to solve the issue!

Very appreciate for your hard work and hope you have a peaceful day😊

I see. On it. I have a solution for it πŸ˜„

I was fetching the version from pyproject.toml. Should be from __init__.py under the boxmot pkg folder. This is now fixed. Thanks for pointing this bug out as well πŸš€