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

AttributeError: 'list' object has no attribute 'device' #11

Closed
SkalskiP opened this issue Feb 22, 2024 · 17 comments · May be fixed by #150
Closed

AttributeError: 'list' object has no attribute 'device' #11

SkalskiP opened this issue Feb 22, 2024 · 17 comments · May be fixed by #150

Comments

@SkalskiP
Copy link

While trying to run detect.py I encountered an error.

command:

!python detect.py --weights /content/weights/yolov9-e.pt --conf 0.1 --source /content/dog.jpeg 

error:

detect: weights=['/content/weights/yolov9-e.pt'], source=/content/dog.jpeg, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.1, 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, dnn=False, vid_stride=1
YOLOv5 🚀 v0.1-2-ge7d68de Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 15102MiB)

Fusing layers... 
Model summary: 1119 layers, 69470144 parameters, 0 gradients, 244.0 GFLOPs
Traceback (most recent call last):
  File "/content/yolov9/detect.py", line 231, in <module>
    main(opt)
  File "/content/yolov9/detect.py", line 226, in main
    run(**vars(opt))
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/content/yolov9/detect.py", line 102, in run
    pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms, max_det=max_det)
  File "/content/yolov9/utils/general.py", line 905, in non_max_suppression
    device = prediction.device
AttributeError: 'list' object has no attribute 'device'

reproducible example

https://colab.research.google.com/drive/1hq-hORpv8pHjwjBz-slPUuKfpXyTXSEg?usp=sharing

@Dragos-Stan
Copy link

    line 903 in utils/general.py 
    prediction = prediction[0][0]  # select only inference output

@spacewalk01
Copy link

spacewalk01 commented Feb 23, 2024

Got same error in detect.py

@WongKinYiu
Copy link
Owner

@Dragos-Stan provides a temporal solution.

To inference yolov9 models, we need follow val_dual.py to construct detect_dual.py. Or do re-parameterization for yolov9 models, then using detect.py.

Currently, re-parametwrization part is under construction.

@spacewalk01
Copy link

It works!

@WongKinYiu
Copy link
Owner

#11 (comment) should be corrected.

    line 903 in utils/general.py 
    prediction = prediction[0][1]  # select only inference output, [0][0] for aux prediction, [0][1] for main prediction.

@spacewalk01
Copy link

So, the correct one is as follows, right?

 line 903 in utils/general.py 
    prediction = prediction[0][1]  

@codewithleo1103
Copy link

So, the correct one is as follows, right?

 line 903 in utils/general.py 
    prediction = prediction[0][1]  

I followed yr ways, it worked with yolov9-c and yolov9-e.
But:

line 903 in utils/general.py 
     prediction = prediction[0] 

worked with gelan-c.pt and gelan-e.pt.

SkalskiP added a commit to SkalskiP/yolov9 that referenced this issue Feb 23, 2024
@SkalskiP
Copy link
Author

Following this discussion, I opened a PR with a (probably temporal) fix. It makes detect.py work with both yolov9 and gelan models.

@noorkhokhar99
Copy link

I am getting the same error and fixed the general.py file as here discussions main...noorkhokhar99:yolov9:patch-1

@mkrupczak3
Copy link

@SkalskiP Your fix is working for me for a yolov9-c model. Haven't tested ELAN.

Is this a better fix than @Dragos-Stan 's given it works for either architecture?

#11 (comment) should be corrected.

    line 903 in utils/general.py 
    prediction = prediction[0][1]  # select only inference output, [0][0] for aux prediction, [0][1] for main prediction.

@SkalskiP
Copy link
Author

SkalskiP commented Mar 1, 2024

Hi @mkrupczak3 👋🏻 My fix should work with both GELAN and YOLOv9 architectures. Take a look here. I use it to run both models.

@mkrupczak3
Copy link

mkrupczak3 commented Mar 2, 2024

@SkalskiP I found your fix applies to detect.py but does not fix val.py. Fixing utils/general.py according to WongKinYiu's comment fixes both however. I'm using that now

@SkalskiP
Copy link
Author

SkalskiP commented Mar 2, 2024

@mkrupczak3 what's wrong with validation? I've done it yesterday and it works for me.

@mkrupczak3
Copy link

mkrupczak3 commented Mar 2, 2024

Altering just detect.py does not fix val.py for dual models such as yolov9-c. Modifying utils/general.py as described does fix val.py however,

mkrupczak3 added a commit to mkrupczak3/yolov9 that referenced this issue Mar 3, 2024
@AndrewHawking
Copy link

    line 903 in utils/general.py 
    prediction = prediction[0][0]  # select only inference output

thanks

@WongKinYiu
Copy link
Owner

    line 903 in utils/general.py 
    prediction = prediction[0][0]  # select only inference output

thanks

#11 (comment)

@xinlin-xiao
Copy link

Following this discussion, I opened a PR with a (probably temporal) fix. It makes work with both and models.detect.py``yolov9``gelan

thanks,its work

Krisha-11 added a commit to Krisha-11/yolov9-fork that referenced this issue Jun 28, 2024
following discussion on WongKinYiu#11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants