aim-uofa / AdelaiDet

AdelaiDet is an open source toolbox for multiple instance-level detection and recognition tasks.
https://git.io/AdelaiDet
Other
3.38k stars 650 forks source link

export_model_to_onnx for SOLOv2 failed #324

Open omerbrandis opened 3 years ago

omerbrandis commented 3 years ago

hello ,

I've tried exporting configs/SOLOv2/R50_3x.yaml to onnx using onnx/export_model_to_onnx.py

failed with : /home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/tensor.py:593: RuntimeWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results). 'incorrect results).', category=RuntimeWarning) Traceback (most recent call last): File "onnx/export_model_to_onnx.py", line 226, in main() File "onnx/export_model_to_onnx.py", line 219, in main keep_initializers_as_inputs=True File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/onnx/init.py", line 230, in export custom_opsets, enable_onnx_checker, use_external_data_format) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/onnx/utils.py", line 91, in export use_external_data_format=use_external_data_format) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/onnx/utils.py", line 639, in _export dynamic_axes=dynamic_axes) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/onnx/utils.py", line 411, in _model_to_graph use_new_jit_passes) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/onnx/utils.py", line 379, in _create_jit_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/onnx/utils.py", line 342, in _trace_and_get_graph_from_model torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/jit/_trace.py", line 1148, in _get_trace_graph outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, kwargs) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/jit/_trace.py", line 130, in forward self._force_outplace, File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/jit/_trace.py", line 116, in wrapper outs.append(self.inner(trace_inputs)) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 725, in _call_impl result = self._slow_forward(input, kwargs) File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 709, in _slow_forward result = self.forward(*input, kwargs) File "/home/ubuntu/AdelaiDet/adet/modeling/solov2/solov2.py", line 108, in forward images = self.preprocess_image(batched_inputs) File "/home/ubuntu/AdelaiDet/adet/modeling/solov2/solov2.py", line 152, in preprocess_image images = [x["image"].to(self.device) for x in batched_inputs] File "/home/ubuntu/AdelaiDet/adet/modeling/solov2/solov2.py", line 152, in images = [x["image"].to(self.device) for x in batched_inputs] IndexError: too many indices for tensor of dimension 3

please advise, Omer.

Sakurayx commented 3 years ago

I have the same problems as you, have you solved them?

AnhNguyen1805 commented 3 years ago

Hi guys, Is that issue solved? Could you share the solution to fix it?!

521alice commented 3 years ago

Hi guys, Is that issue solved? Could you share the solution to fix it?!

have you solved them?

blueardour commented 3 years ago

As far as I know, support for exporting SOLOv2 to onnx is not provided, yet.

This error above is clear. The forward function is not override correctly. Examples can be found in patch_condinst/ patch_blendmask functions in the script.

Takugo commented 3 years ago

@blueardour So which instance segmentation model could be converted into onnx now? I tried some pth models but all failed.