WongKinYiu / yolov9

Implementation of paper - YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
GNU General Public License v3.0
9k stars 1.43k forks source link

Detect AttributeError: 'list' object has no attribute 'device' #333

Open ZYSZYS88 opened 7 months ago

majnas commented 7 months ago

I got same error when evaluating the trained model!

python val.py --device 0 --batch 16 --data data/V2_B20.yaml --img 1280 --weights runs/train/PAC_V2_B20_OY9C_i1280_b64/weights/best.pt --conf 0.001 --iou 0.6

val: data=data/V2_B20.yaml, weights=['runs/train/PAC_V2_B20_OY9C_i1280_b64/weights/best.pt'], batch_size=16, imgsz=1280, conf_thres=0.001, iou_thres=0.6, max_det=300, task=val, device=0, workers=8, single_cls=False, augment=False, verbose=False, save
_txt=False, save_hybrid=False, save_conf=False, save_json=False, project=runs/val, name=exp, exist_ok=False, half=False, dnn=False, min_items=0
YOLO 🚀 v0.1-78-gaa38db1 Python-3.9.18 torch-2.2.1+cu121 CUDA:0 (NVIDIA A40, 45449MiB)                                                                                                                                                                    

Fusing layers...                                                                                                                                                                                                                                          
yolov9-c summary: 604 layers, 50702898 parameters, 0 gradients, 236.6 GFLOPs                                                                                                                                                                              
{'path': '/mnt/D1/PAC/PAC_Versions/V2_B20/images', 'train': '/mnt/D1/PAC/PAC_Versions/V2_B20/images/train', 'val': '/mnt/D1/PAC/PAC_Versions/V2_B20/images/test', 'test': '/mnt/D1/PAC/PAC_Versions/V2_B20/images/test', 'names': {0: 'D40', 1: 'D20', 2: 
'D05'}, 'nc': 3} 
                 Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/713 00:02

Traceback (most recent call last):
  File "/home/s2/avgit/defect_detection/code/yolov9/val.py", line 389, in <module>
    main(opt)
  File "/home/s2/avgit/defect_detection/code/yolov9/val.py", line 362, in main
    run(**vars(opt))
  File "/home/s2/.virtualenvs/av/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/s2/avgit/defect_detection/code/yolov9/val.py", line 201, in run
    preds = non_max_suppression(preds,
  File "/home/s2/avgit/defect_detection/code/yolov9/utils/general.py", line 907, in non_max_suppression
    device = prediction.device
AttributeError: 'list' object has no attribute 'device'
dsbyprateekg commented 7 months ago

Apply the following changes to fix your error-

for yolov9-c and yolov9-e= change line 903 in utils/general.py to- prediction = prediction[0][1]

and for gelan-c.pt and gelan-e.pt= change line 903 in utils/general.py to- prediction = prediction[0]

Huo-Yukang commented 7 months ago

Apply the following changes to fix your error-

for yolov9-c and yolov9-e= change line 903 in utils/general.py to- prediction = prediction[0][1]

and for gelan-c.pt and gelan-e.pt= change line 903 in utils/general.py to- prediction = prediction[0]

After I changed it like this, why is it still the same error?

lyl224459 commented 1 month ago

应用以下更改以修复您的错误 -

对于 yolov9-c 和 yolov9-e=,将 utils/general.py 中的第 903 行更改为 - prediction = prediction[0][1]

对于 gelan-c.pt 和 gelan-e.pt= 将 utils/general.py 中的第 903 行更改为 - prediction = prediction[0]

I changed it like this and it works fine