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

detect.py #50

Closed
hhzhao0525 opened this issue Feb 24, 2024 · 11 comments
Closed

detect.py #50

hhzhao0525 opened this issue Feb 24, 2024 · 11 comments

Comments

@hhzhao0525
Copy link

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?

@WongKinYiu
Copy link
Owner

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

@zahidzqj
Copy link

zahidzqj commented Feb 26, 2024

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

@ASzhaoqiang
Copy link

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

@zahidzqj
Copy link

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?

@hhzhao0525
Copy link
Author

device = prediction[1]

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

@Jaykumaran
Copy link

Jaykumaran commented Mar 1, 2024

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

@rkuo2000
Copy link

rkuo2000 commented Mar 1, 2024

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.

@JFMeyer2k
Copy link

JFMeyer2k commented Mar 2, 2024

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]

@rkuo2000
Copy link

rkuo2000 commented Mar 3, 2024

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

@WongKinYiu
Copy link
Owner

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

@wgqhandsome
Copy link

yolo-*.yaml: use detect_dual.py.

gelan-*.yaml: use detect.py.

Mark. Thank you

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

No branches or pull requests

8 participants