hisfog / SfMNeXt-Impl

[AAAI 2024] Official implementation of "SQLdepth: Generalizable Self-Supervised Fine-Structured Monocular Depth Estimation", and more.
MIT License
91 stars 12 forks source link

Convert to onnx #23

Closed Choi-YeongJoon closed 11 months ago

Choi-YeongJoon commented 12 months ago

I impressed your work! I want to convert pth file (ConvNeXt_Large_SQLdepth) to onnx file. I succeed encorder to onnx, but, unfortunately, I faild to covert depth.pth to onnx.

below is my error code : /SfMNeXt-Impl/networks/layers.py:16: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! assert c == ck, "Number of channels in x and Embedding dimension (at dim 2) of K matrix must match" Traceback (most recent call last): File "export_to_onnx_depth.py", line 56, in input_names=input_names_2, output_names=output_names_2, opset_version=11) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/init.py", line 28, in _export result = utils._export(*args, kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 701, in _export dynamic_axes=dynamic_axes) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 459, in _model_to_graph use_new_jit_passes) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 420, in _create_jit_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 380, in _trace_and_get_graph_from_model torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True) File "/usr/local/lib/python3.6/dist-packages/torch/jit/_trace.py", line 1139, in _get_trace_graph outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, *kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/jit/_trace.py", line 130, in forward self._force_outplace, File "/usr/local/lib/python3.6/dist-packages/torch/jit/_trace.py", line 119, in wrapper outvars, = _flatten(outs) RuntimeError: Only tuples, lists and Variables are supported as JIT inputs/outputs. Dictionaries and strings are also accepted, but their usage is not recommended. Here, received an input of unsupported type: int

I still couldn't find int type, where in this input, output. May I get help?

hisfog commented 12 months ago

It seems that the error is from line 16, in /SfMNeXt-Impl/networks/layers.py. And the line 16 is just an assert. I think you can comment out line 16.

Choi-YeongJoon commented 11 months ago

This issue has been resolved! Thanks, Have a good day :D