2

This is the snipped of my code, dummy_input = torch.randn(800, 1067, 3)

torch.onnx.export(model, dummy_input, "/content/model/detectron2.onnx", opset_version=11)

This is the error it gives:

     22 dummy_input = torch.randn(800, 1067, 3)
---> 23 torch.onnx.export(model, dummy_input, "/content/model/detectron2.onnx", opset_version=11)
     24 
     25 # Export to Caffe2

15 frames
/usr/local/lib/python3.7/dist-packages/detectron2/modeling/meta_arch/rcnn.py in <listcomp>(.0)
    226         Normalize, pad and batch the input images.
    227         """
--> 228         images = [self._move_to_current_device(x["image"]) for x in batched_inputs]
    229         images = [(x - self.pixel_mean) / self.pixel_std for x in images]
    230         images = ImageList.from_tensors(

IndexError: too many indices for tensor of dimension 2

Anyone got any ideas on how to fix this? Any help is appreciated. Thanks

1 Answers1

0

I believe the problem is with your shape of dummy_input. You have provided height, width and channel but the batch is missing.

I would recommend you to use export_model.py present in the tools/deploy folder of detectron2.

Also if you want to know how to properly shape your dummy_data, you can find it in detectron/engine/defaults.py in the call() function.

Good Luck!

  • Thank you for the input of a post from 7 months ago. However, I have already figured out the things that I needed to, and posted on Medium.com about it. Feel free to read it, I appreciate the help though. – Frank van Paassen Feb 13 '23 at 23:38
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33834806) – Daraan Feb 19 '23 at 09:57