Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'float' object is not subscriptable #4

Closed
RioChan opened this issue Dec 16, 2021 · 7 comments
Closed

TypeError: 'float' object is not subscriptable #4

RioChan opened this issue Dec 16, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@RioChan
Copy link

RioChan commented Dec 16, 2021

Traceback (most recent call last):
File "detect.py", line 238, in
main(opt)
File "detect.py", line 233, in main
run(**vars(opt))
File "/root/anaconda3/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "detect.py", line 141, in run
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
File "/opt/edgeai-yolov5/utils/general.py", line 471, in scale_coords
coords[:, [0, 2]] /= gain[1]
TypeError: 'float' object is not subscriptable

May you help to solve this error?
I'm not sure if it can be solved by this way in the ./utils/general.py:

coords[:, [0, 2]] /= gain[1]
coords[:, [1, 3]] /= gain[0]

coords[:, [0, 2]] /= gain

coords[:, [1, 3]] /= gain

@RioChan RioChan added the bug Something isn't working label Dec 16, 2021
@debapriyamaji
Copy link

Can u please share the steps to reproduce the error?

@RioChan
Copy link
Author

RioChan commented Dec 17, 2021

Hi Maji:

I just issue this cmd below and it gives me this error:

root@ubuntu-vm:/opt/edgeai-yolov5# python detect.py --source https://www.youtube.com/watch?v=mMp4UDNII6Q

Traceback (most recent call last):
File "detect.py", line 238, in
main(opt)
File "detect.py", line 233, in main
run(**vars(opt))
File "/root/anaconda3/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "detect.py", line 141, in run
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
File "/opt/edgeai-yolov5/utils/general.py", line 471, in scale_coords
coords[:, [0, 2]] /= gain[1]
TypeError: 'float' object is not subscriptable

BR Rio

@RioChan
Copy link
Author

RioChan commented Dec 17, 2021

Even I issue this cmd, it gives me the same error:

python detect.py --source ./data/images/ --weights yolov5s.pt --conf 0.4

@RioChan
Copy link
Author

RioChan commented Dec 17, 2021

If I made this modification, it seems working okay.
please confirm.

#Original

coords[:, [0, 2]] /= gain[1]

coords[:, [1, 3]] /= gain[0]

#Rio, might fixed, TBC.
coords[:, [0, 2]] /= gain
coords[:, [1, 3]] /= gain

is this Working okay log?

root@ubuntu-vm:/opt/edgeai-yolov5# python detect.py --source ./data/images/ --weights yolov5s.pt --conf 0.4
detect: weights=['yolov5s.pt'], source=./data/images/, imgsz=640, conf_thres=0.4, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False
YOLOv5 🚀 v5.0-324-gca6d78f torch 1.10.1+cu102 CPU

Fusing layers...
/root/anaconda3/lib/python3.6/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2157.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
Model Summary: 213 layers, 7225885 parameters, 0 gradients, 16.5 GFLOPs
image 1/2 /opt/edgeai-yolov5/data/images/bus.jpg: 640x480 3 persons, 1 bus, Done. (0.162s)
image 2/2 /opt/edgeai-yolov5/data/images/zidane.jpg: 384x640 2 persons, 1 tie, Done. (0.107s)
Results saved to runs/detect/exp6
Done. (0.579s)

@RioChan
Copy link
Author

RioChan commented Dec 20, 2021

Hi

Any comments / Feedback?

BR Rio

@debapriyamaji
Copy link

Hi Rio,
This looks fine. Thanks for finding it out. Will fix it.

Regards, Debapriya

@RioChan
Copy link
Author

RioChan commented Dec 20, 2021

Debapriya, thanks, thumb up !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants