hustvl/QueryInst

pytorch2onnx failed

ChicoQ opened this issue · 1 comments

Thank you for your nice work!

I was trying to convert the pre-trained model to ONNX but failed.
Would you be able to direct me a bit? Many thanks.

`

$ python tools/deployment/pytorch2onnx.py
configs/queryinst/queryinst_r50_fpn_300_proposals_crop_mstrain_480-800_3x_coco.py
work_dirs/queryinst_r50_300_queries-6b5ca732.pth
--output-file work_dirs/queryinst_r50_300_queries.onnx
--shape 1333 800
--input-img ./mmdetection/tests/data/color.jpg
--verify

apex is not installed
./.pyenv/versions/QueryInst/lib/python3.7/site-packages/mmcv/utils/misc.py:324: UserWarning: "dropout" is deprecated in FFN.__init__, please use "ffn_drop" instead
f'"{src_arg_name}" is deprecated in '
./.pyenv/versions/QueryInst/lib/python3.7/site-packages/mmcv/cnn/bricks/conv_module.py:151: UserWarning: Unnecessary conv bias before batch/instance norm
'Unnecessary conv bias before batch/instance norm')
Use load_from_local loader
Use load_from_local loader
./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at /pytorch/c10/core/TensorImpl.h:1156.)
return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
./mmdet/models/dense_heads/embedding_rpn_head.py:76: TracerWarning: Using len to get tensor shape might cause the trace to be incorrect. Recommended usage would be tensor.shape[0]. Passing a tensor of different shape might lead to errors or silently give incorrect results.
num_imgs = len(imgs[0])
./mmdet/core/bbox/transforms.py:70: 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:
./.pyenv/versions/QueryInst/lib/python3.7/site-packages/mmcv/ops/roi_align.py:80: 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.size(1) == 5, 'RoI must be (idx, x1, y1, x2, y2)!'
./mmdet/models/roi_heads/query_roi_head.py:163: TracerWarning: Using len to get tensor shape might cause the trace to be incorrect. Recommended usage would be tensor.shape[0]. Passing a tensor of different shape might lead to errors or silently give incorrect results.
rois.new_zeros(len(rois)), # dummy arg
./mmdet/models/roi_heads/bbox_heads/bbox_head.py:511: 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.size(1) == 4 or rois.size(1) == 5, repr(rois.shape)
./mmdet/models/roi_heads/bbox_heads/bbox_head.py:517: 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 bbox_pred.size(1) == 4
./mmdet/models/roi_heads/bbox_heads/bbox_head.py:519: 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 rois.size(1) == 4:
./mmdet/core/bbox/coder/delta_xywh_bbox_coder.py:87: 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 pred_bboxes.size(0) == bboxes.size(0)
./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/tensor.py:575: UserWarning: floor_divide is deprecated, and will be removed in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values.
To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor'). (Triggered internally at /pytorch/aten/src/ATen/native/BinaryOps.cpp:467.)
return torch.floor_divide(self, other)
./mmdet/models/roi_heads/bbox_heads/bbox_head.py:492: TracerWarning: Using len to get tensor shape might cause the trace to be incorrect. Recommended usage would be tensor.shape[0]. Passing a tensor of different shape might lead to errors or silently give incorrect results.
keep_inds[:len(pos_is_gts
)] = pos_keep
./mmdet/core/bbox/transforms.py:110: 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.shape[0] == 0:
./mmdet/core/bbox/transforms.py:114: TracerWarning: Converting a tensor to a NumPy array 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!
bboxes = bboxes.detach().cpu().numpy()
./mmdet/core/bbox/transforms.py:115: TracerWarning: Converting a tensor to a NumPy array 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!
labels = labels.detach().cpu().numpy()
Traceback (most recent call last):
File "tools/deployment/pytorch2onnx.py", line 275, in
dynamic_export=args.dynamic_export)
File "tools/deployment/pytorch2onnx.py", line 77, in pytorch2onnx
dynamic_axes=dynamic_axes)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/onnx/init.py", line 280, in export
custom_opsets, enable_onnx_checker, use_external_data_format)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/onnx/utils.py", line 94, in export
use_external_data_format=use_external_data_format)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/onnx/utils.py", line 695, in _export
dynamic_axes=dynamic_axes)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/onnx/utils.py", line 459, in _model_to_graph
_retain_param_name)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/onnx/utils.py", line 422, in _create_jit_graph
graph, torch_out = _trace_and_get_graph_from_model(model, args)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/onnx/utils.py", line 373, in _trace_and_get_graph_from_model
torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/jit/_trace.py", line 1160, in _get_trace_graph
outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/jit/_trace.py", line 132, in forward
self._force_outplace,
File "./.pyenv/versions/QueryInst/lib/python3.7/site-packages/torch/jit/_trace.py", line 121, in wrapper
out_vars, _ = _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: numpy.ndarray

`

We didn't test pytorch2onnx, but we will soon add QueryInst to mmdetection toolbox.

Here, we only deal with issues that claimed cannot reproduce the results reported in our paper. It is unlikely for us to solve other problems.

I'm closing this issue but let us know if you have any further questions related to reproducing the COCO results.