When I try to convert pytorch model to onnx by running tools/pytorch2onnx.py, I encountered this error.
/content/anaconda3/envs/face/lib/python3.7/site-packages/mmdet-1.1.0+fb1fdd7-py3.7-linux-x86_64.egg/mmdet/core/bbox/transforms.py:163: 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!
if bboxes.size(0) > 0:
/content/anaconda3/envs/face/lib/python3.7/site-packages/mmdet-1.1.0+fb1fdd7-py3.7-linux-x86_64.egg/mmdet/models/roi_extractors/single_level.py:99: 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!
if inds.any():
/content/anaconda3/envs/face/lib/python3.7/site-packages/mmdet-1.1.0+fb1fdd7-py3.7-linux-x86_64.egg/mmdet/ops/roi_align/roi_align.py:149: 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 rois.dim() == 2 and rois.size(1) == 5
Traceback (most recent call last):
File "tools/pytorch2onnx.py", line 127, in <module>
main()
File "tools/pytorch2onnx.py", line 119, in main
onnx_model = export_onnx_model(model, (input_data,), args.passes)
File "tools/pytorch2onnx.py", line 44, in export_onnx_model
operator_export_type=OperatorExportTypes.ONNX_ATEN_FALLBACK,
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/onnx/__init__.py", line 132, in export
strip_doc_string, dynamic_axes)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/onnx/utils.py", line 64, in export
example_outputs=example_outputs, strip_doc_string=strip_doc_string, dynamic_axes=dynamic_axes)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/onnx/utils.py", line 329, in _export
_retain_param_name, do_constant_folding)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/onnx/utils.py", line 213, in _model_to_graph
graph, torch_out = _trace_and_get_graph_from_model(model, args, training)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/onnx/utils.py", line 171, in _trace_and_get_graph_from_model
trace, torch_out = torch.jit.get_trace_graph(model, args, _force_outplace=True)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/jit/__init__.py", line 256, in get_trace_graph
return LegacyTracedModule(f, _force_outplace, return_inputs)(*args, **kwargs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/jit/__init__.py", line 323, in forward
out = self.inner(*trace_inputs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/nn/modules/module.py", line 545, in __call__
result = self._slow_forward(*input, **kwargs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/nn/modules/module.py", line 531, in _slow_forward
result = self.forward(*input, **kwargs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/mmdet-1.1.0+fb1fdd7-py3.7-linux-x86_64.egg/mmdet/models/detectors/two_stage.py", line 128, in forward_dummy
cls_score, bbox_pred = self.bbox_head(bbox_feats)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/nn/modules/module.py", line 545, in __call__
result = self._slow_forward(*input, **kwargs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/torch/nn/modules/module.py", line 531, in _slow_forward
result = self.forward(*input, **kwargs)
File "/content/anaconda3/envs/face/lib/python3.7/site-packages/mmdet-1.1.0+fb1fdd7-py3.7-linux-x86_64.egg/mmdet/core/fp16/decorators.py", line 130, in new_func
return old_func(*args, **kwargs)
TypeError: forward() missing 2 required positional arguments: 'feats' and 'rois'
When I try to convert pytorch model to onnx by running tools/pytorch2onnx.py, I encountered this error.
Script
Environment
sys.platform: linux
Python: 3.7.5 (default, Oct 25 2019, 15:51:11) [GCC 7.3.0]
CUDA available: True
CUDA_HOME: /usr/local/cuda-10.1
NVCC: Cuda compilation tools, release 10.1, V10.1.105
GPU 0: GeForce RTX 2080 Ti
GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
PyTorch: 1.2.0
PyTorch compiling details: PyTorch built with:
TorchVision: 0.4.0
OpenCV: 4.1.1
MMCV: 0.4.3
MMDetection: 1.1.0+fb1fdd7
MMDetection Compiler: GCC 5.4
MMDetection CUDA Compiler: 10.1
Error traceback
Thanks a lot!