0

I want to convert a model into onnx But when I import caffe2_export for exporting model to onnx I get this error

from detectron2.export import caffe2_export

ERROR import onnx.optimizer ModuleNotFoundError: No module named 'onnx.optimizer'

MT0
  • 143,790
  • 11
  • 59
  • 117
  • A similar issue seems to be tracked on the official GitHub Detectron2 repository: https://github.com/facebookresearch/detectron2/issues/3488#issuecomment-1044512648 – thomaskleiven Nov 30 '22 at 09:04

2 Answers2

0

It is because onnxoptimizer has been removed since onnx version 1.9.

If you really do need to use it, you can install onnx version 1.8.

pip install onnx==1.8.1

NOTE: I do not recommend this method.

If you really want to export a model into an onnx format, I'd recommend you to use export_model.py.

0

For anyone else that comes across this, exporting a Detectron2 model to ONNX format is not straightforward at all. The export includes operations which require Caffe2, and these then need to be replaced.

Someone's managed it here, but I can't replicate it https://github.com/NVIDIA/TensorRT/issues/2546

MMDetection is very similar to Detectron2, but exports are much better supported.

George Pearse
  • 59
  • 1
  • 5