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

Trying to export a segment model -- "IndexError: index 1 is out of bounds for dimension 0 with size 1" #472

Open
leah-at-lovelace opened this issue Jun 5, 2024 · 5 comments

Comments

@leah-at-lovelace
Copy link

leah-at-lovelace commented Jun 5, 2024

I'm trying to convert yolov9-c-seg.pt to ONNX, using export.py, but I get the following error. Has anyone else hit this?

One note is that I had to make a change to get segment/predict.py running. After pred, proto = model(im, augment=augment, visualize=visualize)[:2] I added proto = proto[2] based on another issue I found here. Not sure it's relevant to my current error, but possibly.

YOLO 🚀 2024-6-4 Python-3.12.3 torch-2.3.0 CPU

Fusing layers... 
yolov9-c-dseg-hrsid summary: 746 layers, 57468582 parameters, 0 gradients, 368.6 GFLOPs
Traceback (most recent call last):
  File "/Users/<...>/yolov9/export.py", line 979, in <module>
    main(opt)
  File "/Users/<...>/yolov9/export.py", line 974, in main
    run(**vars(opt))
  File "/Users/<...>/miniconda3/envs/yolov9/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<...>/yolov9/export.py", line 754, in run
    y = model(im)  # dry runs
        ^^^^^^^^^
  File "/Users/<...>/miniconda3/envs/yolov9/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<...>/miniconda3/envs/yolov9/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<...>/yolov9/models/yolo.py", line 947, in forward
    return self._forward_once(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/<...>/yolov9/models/yolo.py", line 810, in _forward_once
    x = m(x)  # run
        ^^^^
  File "/Users/<...>/miniconda3/envs/yolov9/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<...>/miniconda3/envs/yolov9/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<...>/yolov9/models/yolo.py", line 754, in forward
    return (torch.cat([d[0][1], mc[1]], 1), (d[1][1], mc[1], p[1]))
                       ~~~~^^^
IndexError: index 1 is out of bounds for dimension 0 with size 1
@janb14
Copy link

janb14 commented Jun 9, 2024

Yes i encountered the same error with a trained segmentation model ;(

@janb14
Copy link

janb14 commented Jun 13, 2024

It seems to have something to do with the preperation of the dual models outputs when in eval mode. Logically i tried to change the line to return (torch.cat([d[0], mc[1]], 1), (d[1], mc[1], p[1])), then the export works. But when using the onnx for inference, it does not produce 2 output tensors as expected but 4 and they are malformed. For now im falling back onto the gelan models that do work, including the export to onnx. :/ maybe someone smarter than me knows how to concat the resulting tensors correctly.

@fukingbus
Copy link

failed to export weight trained using train_dual too, any update on this?
the dual model are more precise compared to the one trained using gelan 🫡

@Ultraopxt
Copy link

same error!

@jabuarab
Copy link

Shouldn't it be (torch.cat([d[0], mc[0]], 1), (d[1], mc[1], p[1])) ?

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

5 participants