yolov9 icon indicating copy to clipboard operation
yolov9 copied to clipboard

`AttributeError: 'list' object has no attribute 'device'`

Open SkalskiP opened this issue 1 year ago • 9 comments

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

SkalskiP avatar Feb 22 '24 16:02 SkalskiP

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

Dragos-Stan avatar Feb 22 '24 19:02 Dragos-Stan

Got same error in detect.py

spacewalk01 avatar Feb 23 '24 00:02 spacewalk01

@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.

WongKinYiu avatar Feb 23 '24 00:02 WongKinYiu

It works!

spacewalk01 avatar Feb 23 '24 01:02 spacewalk01

https://github.com/WongKinYiu/yolov9/issues/11#issuecomment-1960078993 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.

WongKinYiu avatar Feb 23 '24 01:02 WongKinYiu

So, the correct one is as follows, right?

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

spacewalk01 avatar Feb 23 '24 01:02 spacewalk01

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.

codewithleo1103 avatar Feb 23 '24 03:02 codewithleo1103

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

SkalskiP avatar Feb 23 '24 08:02 SkalskiP

I am getting the same error and fixed the general.py file as here discussions https://github.com/WongKinYiu/yolov9/compare/main...noorkhokhar99:yolov9:patch-1

noorkhokhar99 avatar Feb 23 '24 15:02 noorkhokhar99

@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.

mkrupczak3 avatar Mar 01 '24 04:03 mkrupczak3

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

SkalskiP avatar Mar 01 '24 06:03 SkalskiP

@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

mkrupczak3 avatar Mar 02 '24 18:03 mkrupczak3

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

SkalskiP avatar Mar 02 '24 18:03 SkalskiP

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 avatar Mar 02 '24 20:03 mkrupczak3

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

thanks

AndrewHawking avatar Mar 04 '24 02:03 AndrewHawking

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

thanks

https://github.com/WongKinYiu/yolov9/issues/11#issuecomment-1960610186

WongKinYiu avatar Mar 04 '24 02:03 WongKinYiu

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

xinlin-xiao avatar May 15 '24 03:05 xinlin-xiao

Use detect_dual.py instead of detect.py

rammalali avatar Aug 20 '24 07:08 rammalali