yolov9 icon indicating copy to clipboard operation
yolov9 copied to clipboard

detect.py

Open hhzhao0525 opened this issue 1 year ago • 9 comments

device = prediction[1] mps = 'mps' in device.type # Apple MPS if mps: # MPS not fully supported yet, convert tensors to CPU before NMS prediction = prediction.cpu() bs = prediction.shape[0] # batch size nc = prediction.shape[1] - nm - 4 # number of classes mi = 4 + nc # mask start index xc = torch.max(prediction[:, 4:mi], dim=1)[0] > conf_thres TypeError: argument of type 'builtin_function_or_method' is not iterable,The function or method does not support iterable,how to slove it?

hhzhao0525 avatar Feb 24 '24 07:02 hhzhao0525

I do not know meaning of device = prediction[1].

WongKinYiu avatar Feb 24 '24 08:02 WongKinYiu

I do not know meaning of device = prediction[1].

应该是书写错误了吧

我在运行detect.py时,发现prediction是[[[tesnor ... ], [tesnor ...]], [[tesnor ... ], [tesnor ...]]],在nms的时候必须按照下面的方式获取数据才不会报错,不知道为何会这样: if isinstance(prediction, (list, tuple)): # YOLO model in validation model, output = (inference_out, loss_out) # prediction = prediction[0] # select only inference output yolov9源代码
prediction = prediction[0][0] # select only inference output zqj20240226 # prediction = prediction[0][1] # select only inference output zqj20240226 device = prediction.device

zahidzqj avatar Feb 26 '24 07:02 zahidzqj

I do not know meaning of device = prediction[1].

应该是书写错误了吧

我在运行detect.py时,发现prediction是[[[tesnor ... ], [tesnor ...]], [[tesnor ... ], [tesnor ...]]],在nms的时候必须按照下面的方式获取数据才不会报错,不知道为何会这样: if isinstance(prediction, (list, tuple)): # YOLO model in validation model, output = (inference_out, loss_out) # prediction = prediction[0] # select only inference output yolov9源代码 prediction = prediction[0][0] # select only inference output zqj20240226 # prediction = prediction[0][0] # select only inference output zqj20240226 device = prediction.device

although not ERROR , only solves the first pic of folder... if you want to apply NMS to every pic, just iterate

ASzhaoqiang avatar Feb 26 '24 07:02 ASzhaoqiang

I do not know meaning of device = prediction[1].

应该是书写错误了吧

我在运行detect.py时,发现prediction是[[[tesnor ... ], [tesnor ...]], [[tesnor ... ], [tesnor ...]]],在nms的时候必须按照下面的方式获取数据才不会报错,不知道为何会这样: if isinstance(prediction, (list, tuple)): # YOLO model in validation model, output = (inference_out, loss_out) # prediction = prediction[0] # select only inference output yolov9源代码 prediction = prediction[0][0] # select only inference output zqj20240226 # prediction = prediction[0][0] # select only inference output zqj20240226 device = prediction.device

I do not know meaning of device = prediction[1].

应该是书写错误了吧

我在运行detect.py时,发现prediction是[[[tesnor ... ], [tesnor ...]], [[tesnor ... ], [tesnor ...]]],在nms的时候必须按照下面的方式获取数据才不会报错,不知道为何会这样: if isinstance(prediction, (list, tuple)): # YOLO model in validation model, output = (inference_out, loss_out) # prediction = prediction[0] # select only inference output yolov9源代码 prediction = prediction[0][0] # select only inference output zqj20240226 # prediction = prediction[0][1] # select only inference output zqj20240226 device = prediction.device

Why are there two results and there is a difference between them?

zahidzqj avatar Feb 27 '24 00:02 zahidzqj

device = prediction[1]

The correct writing should be: "device = prediction.device."

hhzhao0525 avatar Feb 28 '24 09:02 hhzhao0525

For list device not found ,under utils->general.py change line 903 as prediction = prediction[0][1] for yolov9-c.pt or yolov9-e.pt. However for yolov9-c-converted you can run repo without any change

Jaykumaran avatar Mar 01 '24 11:03 Jaykumaran

For list device not found ,under utils->general.py change line 903 as prediction = prediction[0][1] for yolov9-c.pt or yolov9-e.pt. However for yolov9-c-converted you can run repo without any change

Thanks a lot, it works.

rkuo2000 avatar Mar 01 '24 13:03 rkuo2000

After I trained a yolov9-e model, I wanted to run inference using detect.py with

python3 detect.py --weights $EC_MODEL_PATH --conf-thres 0.1 --imgsz 640 --source $EC2_INPUT_PATH --project $EC2_OUTPUT_PATH --device 0 --nosave --save-txt

where $EC_MODEL_PATH is the path to the model, $EC2_INPUT_PATH is the place where the images are I want to run the inference for, and $EC2_OUTPUT_PATH is the path where the output is supposed to be written to.

I run into the error:

[ec2-user@ip-xxx-xxx-xxx-xxx yolov9]$ python3 detect.py --weights $EC_MODEL_PATH --conf-thres 0.1 --imgsz 640 --source $EC2_INPUT_PATH --project $EC2_OUTPUT_PATH --device 0 --nosave --save-txt
detect: weights=['/home/ec2-user/yolo/yolov9//runs/train/yolov9-e4/weights/best.pt'], source=/home/ec2-user/yolo/images/inference/Test/GoPro_Academy_Dubai_vs_Banaat_FC/images_tiled, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.1, iou_thres=0.45, max_det=1000, device=0, view_img=False, save_txt=True, save_conf=False, save_crop=False, nosave=True, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=/home/ec2-user/yolo/yolov9/runs/val/, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 🚀 v0.1-26-g6d91e97 Python-3.10.9 torch-2.2.1+cu121 CUDA:0 (NVIDIA A10G, 22516MiB)

Fusing layers... 
yolov9-e summary: 839 layers, 68547814 parameters, 0 gradients, 240.7 GFLOPs
Traceback (most recent call last):
  File "/home/ec2-user/yolo/yolov9/detect.py", line 231, in <module>
    main(opt)
  File "/home/ec2-user/yolo/yolov9/detect.py", line 226, in main
    run(**vars(opt))
  File "/opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/ec2-user/yolo/yolov9/detect.py", line 102, in run
    pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms, max_det=max_det)
  File "/home/ec2-user/yolo/yolov9/utils/general.py", line 905, in non_max_suppression
    device = prediction.device
AttributeError: 'list' object has no attribute 'device'

The error got fixed as per Jaykumaran suggestion by chaging line 903 within /utils/general.py

from: prediction = prediction[0] # select only inference output

to: prediction = prediction[0][1]

JFMeyer2k avatar Mar 02 '24 16:03 JFMeyer2k

detect.py working on Kaggle after using prediction = prediction[0][1] in /utils/general.py

rkuo2000 avatar Mar 03 '24 12:03 rkuo2000

yolo-*.yaml: use detect_dual.py. gelan-*.yaml: use detect.py.

WongKinYiu avatar Mar 10 '24 09:03 WongKinYiu

yolo-*.yaml: use detect_dual.py.

gelan-*.yaml: use detect.py.

Mark. Thank you

wgqhandsome avatar Mar 10 '24 09:03 wgqhandsome