TexasInstruments / edgeai-yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite. Forked from https://ultralytics.com/yolov5
https://github.com/TexasInstruments/edgeai
GNU General Public License v3.0
649 stars 120 forks source link

Export onnx model settings: export_nms=true #3

Closed Serissa closed 2 years ago

Serissa commented 2 years ago

I am not sure about the export.py file, nms = NMS(conf=0.001) nms_export = NMS_Export(conf=0.001) y_export = nms_export(y) y = nms(y) assert (torch.sum(torch.abs(y_export[0]-y[0]))<1e-6) What should I do if y_export is inconsistent with y? Could you help check this case? Thanks.

debapriyamaji commented 2 years ago

@Serissa , It should ideally match. Can you share the ckpt so that I can reproduce the error.

Regards, Debapriya

ppogg commented 2 years ago

Maybe I have the same problem:

(py36) E:\pytorch\edgeai-yolov5-yolo-pose>python export.py --weights weights/Yolov5s6_pose_640_ti_lite.pt  --img 960 --batch 1 --simplify --export-nms
Namespace(batch_size=1, device='0', dynamic=False, export_nms=True, grid=False, img_size=[960, 960], simplify=True, weights='weights/Yolov5s6_pose_640_ti_lite.pt')
YOLOv5  2022-6-6 torch 1.8.1+cu101 CUDA:0 (NVIDIA GeForce GTX 950M, 2048.0MB)

Fusing layers...
Model Summary: 297 layers, 12349624 parameters, 0 gradients, 16.8 GFLOPS
Traceback (most recent call last):
  File "export.py", line 79, in <module>
    print(nms_export(y))
  File "D:\Anaconda\conda\envs\py36\Lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "E:\pytorch\edgeai-yolov5-yolo-pose\models\common.py", line 275, in forward
    return non_max_suppression_export(x[0], conf_thres=self.conf, iou_thres=self.iou, classes=self.classes, kpt_label=self.kpt_label)
  File "E:\pytorch\edgeai-yolov5-yolo-pose\utils\general.py", line 606, in non_max_suppression_export
    conf, j = cls_conf.max(1, keepdim=True)
RuntimeError: cannot perform reduction function max on tensor with no elements because the operation does not have an identity

And this is the result of nms(y): [tensor([], device='cuda:0', size=(0, 6))] The other one is num_export(y): tensor([], device='cuda:0', size=(0, 0)) Aha, maybe something went wrong~

nomaad42 commented 1 year ago

@ppogg I have the same problem, have you managed to solve it?

nomaad42 commented 1 year ago

@ppogg I have the same problem, have you managed to solve it?

Solved this problem by setting "conf=0.001"