mmaction2
mmaction2 copied to clipboard
Error While Exporting Model to ONNX
I was trying to convert SlowFast and SlowOnly models to ONNX and I'm getting the following error, can anyone help?
load checkpoint from local path: checkpoints/slow_only/slowonly_omnisource_pretrained_r101_8x8x1_20e_ava_rgb_20201217-16378594.pth
/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/utils.py:356: UserWarning: Model has no forward function
warnings.warn("Model has no forward function")
Traceback (most recent call last):
File "tools/deployment/pytorch2onnx.py", line 170, in <module>
verify=args.verify)
File "tools/deployment/pytorch2onnx.py", line 75, in pytorch2onnx
opset_version=opset_version)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/__init__.py", line 320, in export
custom_opsets, enable_onnx_checker, use_external_data_format)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/utils.py", line 111, in export
custom_opsets=custom_opsets, use_external_data_format=use_external_data_format)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/utils.py", line 729, in _export
dynamic_axes=dynamic_axes)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/utils.py", line 493, in _model_to_graph
graph, params, torch_out, module = _create_jit_graph(model, args)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/utils.py", line 437, in _create_jit_graph
graph, torch_out = _trace_and_get_graph_from_model(model, args)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/onnx/utils.py", line 388, 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/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/jit/_trace.py", line 1166, in _get_trace_graph
outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/jit/_trace.py", line 132, in forward
self._force_outplace,
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/jit/_trace.py", line 118, in wrapper
outs.append(self.inner(*trace_inputs))
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/j_dev/anaconda3/envs/mm2/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1090, in _slow_forward
result = self.forward(*input, **kwargs)
TypeError: forward_dummy() got an unexpected keyword argument 'softmax'
I think you can edit forward_dummy() in slowfast model to make it supprt softmax arg
@jamiechoi1995 the error is not originating from the model.py file, its coming from internal files of ONNX, are you asking me to make modifications in package files?
@junaid340 Yes, you can make modifications in package files as a workaround. Or just do not pass the softmax arg
forward_dummy() is only used when exporting onnx. Thus it goes well when training or inference using py.
However, I think mmaction should support this arg https://github.com/open-mmlab/mmaction2/blob/a067e27b3b5e399f054b89cf2cacd2c50274e0d2/mmaction/models/recognizers/recognizer3d.py#L101
@jamiechoi1995 actually Im not passing softmax arg. That is why it bugs me! that its getting an argument which I didn't even passed! But sure I'll try to make some changes in the package files to see if it works!
And the model that Im trying to convert is not from recognizers its from the configs/detection/ava/slowfast_kinetic*****.py
I don't think MMAction2 support exxporting spatio-temporal action detection models for now.
@junaid340 : were you able to resolve this error? I get same error with slowfast network.
@rdabane the issue was that ONNX currently didn't supported the above mentioned models for conversions. So it was a dead end for me!
@junaid340 : I was able to export slowfast to onnx by following change in mmaction/models/recognizers/recognizer3d.py
- def forward_dummy(self, imgs, softmax=False):
+ def forward_dummy(self, imgs, ignore, softmax=False):