Zed Examples YoloV5 custom detection needs update

When following the instructions on zed-examples/object detection/custom detector/python/pytorch_yolov5 at master · stereolabs/zed-examples · GitHub we encountered an issue:

The installation went flawlessly but there seems to be an incompatibility issue with the newest version (commit #10220 SHA: 6992dde4bd628f6bffe7d4c5025afadf79ed679b of yoloV5:

When executing python detector.py with the specified parameters, we encountered:

ImportError: cannot import name ‘scale_coords’ from ‘utils.general’

The detection window did not open.

In some version of yoloV5, presumably commit #9570 on Sept. 24 2022:

“new scale_segments() function” the scale_coords function was changed to the scale_segments function. We tried earlier commits which at least opened the detection window but with a black screen and further issues arose:

“/home/(my paths)…/yolov5/detector.py”, line 100, in torch_thread
model = attempt_load(weights, map_location=device) # load FP32
TypeError: attempt_load() got an unexpected keyword argument ‘map_location’

The attempt_load() function apparently does not accept this argument.
We went down the road of even older commits but at one point there was an issue with the pytorch version, because the yoloV5 repo we chose was so old.

If you have any help or further questions please do not hesitate to ask. We think that an updated version of detector.py might fix the problem.

Thank you!!

Hello, thank you for the notice. We’ll check this out.

Antoine

1 Like

Thank you! FYI I think I forgot to mention that we use linux (pop!_OS), but you probably recognized it was linux from the Folder path.

Moritz

HI there! i am facing the similar issue with the detector.py which is
ImportError: cannot import name ‘scale_coords’ from ‘utils.general’
as someone mentioned in this post, after scale_coords changes to scale_segments still there are problems arose. did anyone solve detector.py errors without any problem ? if yes please feel free to suggest me.
My task is to track the objects along with their 3D information using Zed-2i. if anyone has any idea how it can be achieved please share your inputs.
Thank you
Parvathi

Hello @parvathi , still waiting for a fix, since this is beyond my experience :confused:

Hi, I faced this exact issue and appear to have got it working by checking out an older version of the yolov5 repo, this one worked for me -

Also in detector.py the line
model = attempt_load(weights, map_location=device)
needs to be changed to
model = attempt_load(weights, device=device)

This post was helpful for finding that out - 关于“TypeError: attempt_load() got an unexpected keyword argument 'map_location'” · Issue #8178 · ultralytics/yolov5 · GitHub

hope this helps

1 Like

@sttteephen Thank you very much, this solved the Problem!
@alassagne Perhaps an adjustment is still required, this is a very good lead.

This is the actual solution. It’s difficult for us to follow every version of every yolov(x), so we have to stay at a specific commit. The problem is, the documentation seems better on the C++ sample, sorry for that. We’ll improve the python documentation.

1 Like

Hello, can you be more specific about the exact yolov5 branch that worked for your python code? I’ve tried a few but always had mismatches in the interpreter or a blank screen in a window.
Thank you for the information and for helping out.

@sttteephen already pointed out the Version in his reply:

Just click on the link in his reply in this very same thread and adapt detector.py accordingly, as he says.

When you click “Browse files” on the right side, it leads you to the code which you can download as a ZIP file: GitHub - ultralytics/yolov5 at d669a74623f273f74213a88b5233964d1ab3ea08

We need to use YOLOv5-6.1version, Beacuse the new version ‘scale_coords’ rename to ‘scale_boxes’ .

Sorry for the late response…
Verified on linux and jetson SDK computers.
Many thanks for the tips to every one of this chain.
momi193, your tip on the link to the code is great!

1 Like

I am not sure if the following issue analysis is valid for this chain.

Bounding box of the detected object gets far longer height calculation in the xywh2abcd(xywh, im_shape) function. I’ve tested this from the latest sdk 4.0 down to 3.6.5 .
What could be the root cause for this?

A problematic bounding box display:

A good bounding box display:

I’m trying to use custom object detection python on jetson orin agx jet pack 5.1.1 with zed sdk ZED_SDK_Tegra_L4T35.3_v4.0.1.zstd and yolov5 v7.0.
In result, I’m getting Exception of AttributeError regarding the “DETECTION_MODEL” in line 166 of the detector.py script see below.

result of running command: python3 detector.py --weights yolov5m.pt
Intializing Network…
Initializing Camera…
Initialized Camera
Traceback (most recent call last):
File “detector.py”, line 256, in
main()
File “detector.py”, line 166, in main
obj_param.detection_model = sl.DETECTION_MODEL.CUSTOM_BOX_OBJECTS
AttributeError: module ‘pyzed.sl’ has no attribute ‘DETECTION_MODEL’
YOLOv5 :rocket: v7.0-151-g3e14883 Python-3.8.10 torch-2.0.0 CPU

Fusing layers…
YOLOv5m_v6 summary: 290 layers, 21172173 parameters, 0 gradients
^CException ignored in: <module ‘threading’ from ‘/usr/lib/python3.8/threading.py’>
Traceback (most recent call last):
File “/usr/lib/python3.8/threading.py”, line 1388, in _shutdown
lock.acquire()
KeyboardInterrupt:

result of running in the debugger
Exception has occurred: AttributeError
module ‘pyzed.sl’ has no attribute ‘DETECTION_MODEL’
File “/usr/local/zed/samples/object detection/custom detector/python/pytorch_yolov5/detector.py”, line 166, in main
obj_param.detection_model = sl.DETECTION_MODEL.CUSTOM_BOX_OBJECTS
File “/usr/local/zed/samples/object detection/custom detector/python/pytorch_yolov5/detector.py”, line 256, in
main()
AttributeError: module ‘pyzed.sl’ has no attribute ‘DETECTION_MODEL’