MhLiao / DB

A PyTorch implementation of "Real-time Scene Text Detection with Differentiable Binarization".
2.11k stars 481 forks source link

Error when converting checkpoint to ONNX #362

Open gigasurgeon opened 1 year ago

gigasurgeon commented 1 year ago

I am getting this error when I am trying to convert checkpoint to ONNX.

torch version = 1.13.1+cu116

python3 convert_to_onnx.py /vmdata/amitsingh/workspace/z2/DB/experiments/seg_detector/my_custom.yaml /vmdata/amitsingh/workspace/z2/DB/outputs/workspace/DB/SegDetectorModel-seg_detector/deformable_resnet50/L1BalanceCELoss/model/final output.onnx


verbose: True
Initializing log dir for workspace/SegDetectorModel-seg_detector/deformable_resnet50/L1BalanceCELoss
/vmdata/amitsingh/workspace/z2/dataset_download_from_deeplabel_and_convert_to_TD500_format/DBnet_TD500_format_dataset
Resumed from /vmdata/amitsingh/workspace/z2/DB/outputs/workspace/DB/SegDetectorModel-seg_detector/deformable_resnet50/L1BalanceCELoss/model/final
Traceback (most recent call last):
  File "convert_to_onnx.py", line 81, in <module>
    main()
  File "convert_to_onnx.py", line 23, in main
    Demo(experiment, experiment_args, cmd=args).inference()
  File "convert_to_onnx.py", line 75, in inference
    torch.onnx.export(model.model.module, img, self.output_path, input_names=['input'],
  File "/vmdata/amitsingh/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 504, in export
    _export(
  File "/vmdata/amitsingh/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 1529, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/vmdata/amitsingh/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 1115, in _model_to_graph
    graph = _optimize_graph(
  File "/vmdata/amitsingh/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 605, in _optimize_graph
    _C._jit_pass_peephole(graph, True)
IndexError: Argument passed to at() was not in the map.
minh132 commented 1 year ago

Have you fixed this error yet? @gigasurgeon

minh132 commented 1 year ago

@MhLiao can you help me fix this error

GermanDeer commented 1 year ago

@MhLiao can you help me fix this error

https://github.com/pytorch/pytorch/pull/104067

Try installing PyTorch 2.1.0 with CUDA 11.8, and use argument autograd_inlining=False:

torch.onnx.export(model.model.module, img, self.output_path, input_names=['input'],
                              output_names=['output'], dynamic_axes=dynamic_axes,
                              verbose=False, opset_version=12, autograd_inlining=False)

It helps with this error, but there is another one: issue

Obezyan0941 commented 1 month ago

Here is the solution that worked for me with autograd_inlining=False option: https://github.com/open-mmlab/mmagic/issues/63