Closed hbchen-hf closed 3 years ago
@hbchen-hf Hi, could you provide detailed info about this issue?
mmd:2.12.0 mmcv:1.3.3 CUDA:10.1
python tools/deployment/pytorch2onnx.py cascade_rcnn_s101_fpn-backbone+head_mstrain-range_1x.py epoch_12.pth --input-img 00168116.jpg --output-file tmp.onnx --verify
/data/hbchen/mmdetection/mmdet/models/builder.py:52: UserWarning: train_cfg and test_cfg is deprecated, please specify them in model
'please specify them in model', UserWarning)
Use load_from_local loader
Use load_from_local loader
/data/hbchen/mmdetection/mmdet/models/dense_heads/anchor_head.py:573: TracerWarning: Converting a tensor to a Python index 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!
img_metas[i]['scale_factor'] for i in range(cls_scores[0].shape[0])
/data/hbchen/mmdetection/mmdet/models/dense_heads/rpn_head.py:123: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
cfg.nms_pre, device=cls_scores[0].device, dtype=torch.long)
/data/hbchen/mmdetection/mmdet/models/dense_heads/rpn_head.py:127: 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 rpn_cls_score.size()[-2:] == rpn_bbox_pred.size()[-2:]
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:62: 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 k <= 0 or size <= 0:
/data/hbchen/mmdetection/mmdet/models/dense_heads/rpn_head.py:146: 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 nms_pre > 0:
/data/hbchen/mmdetection/mmdet/models/dense_heads/rpnhead.py:147: TracerWarning: Converting a tensor to a Python integer 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!
, topk_inds = scores.topk(nms_pre)
/data/hbchen/mmdetection/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)
/data/hbchen/mmdetection/mmdet/core/bbox/coder/delta_xywh_bbox_coder.py:89: 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(1) == bboxes.size(1)
/data/hbchen/mmdetection/mmdet/models/dense_heads/rpn_head.py:192: UserWarning: In rpn_proposal or test_cfg, nms_thr has been moved to a dict named nms as iou_threshold, max_num has been renamed as max_per_img, name of original arguments and the way to specify iou_threshold of NMS will be deprecated.
'In rpn_proposal or test_cfg, '
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:118: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
iou_threshold = torch.tensor([iou_threshold], dtype=torch.float32)
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:119: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
score_threshold = torch.tensor([score_threshold], dtype=torch.float32)
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:123: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
nms_pre = torch.tensor(pre_top_k, device=scores.device, dtype=torch.long)
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:126: 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 nms_pre > 0:
/data/hbchen/mmdetection/mmdet/core/export/onnxhelper.py:128: TracerWarning: Converting a tensor to a Python integer 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!
, topk_inds = max_scores.topk(nms_pre)
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:147: TracerWarning: Converting a tensor to a Python integer 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!
batch_inds = torch.randint(batch_size, (num_fake_det, 1))
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:148: TracerWarning: Converting a tensor to a Python integer 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!
cls_inds = torch.randint(num_class, (num_fake_det, 1))
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:149: TracerWarning: Converting a tensor to a Python integer 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!
box_inds = torch.randint(num_box, (num_fake_det, 1))
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:171: TracerWarning: There are 2 live references to the data region being modified when tracing in-place operator indexput. This might cause the trace to be incorrect, because all other views that also reference this data will not reflect this change in the trace! On the other hand, if all other views use the same memory chunk, but are disjoint (e.g. are outputs of torch.split), this might still be safe.
mask[pos_inds, :] += 1
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:180: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
after_top_k, device=scores.device, dtype=torch.long)
/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py:183: 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 nms_after > 0:
/data/hbchen/mmdetection/mmdet/core/export/onnxhelper.py:184: TracerWarning: Converting a tensor to a Python integer 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!
, topk_inds = scores.topk(nms_after)
/data/hbchen/mmdetection/mmdet/models/roi_heads/cascade_roi_head.py:281: TracerWarning: Converting a tensor to a Python index 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!
num_imgs = len(proposal_list)
/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/tensor.py:426: 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)
/data/hbchen/mmdetection/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:
/data/hbchen/mmcv/mmcv/ops/roi_align.py:79: 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)!'
/data/hbchen/mmdetection/mmdet/models/roi_heads/cascade_roi_head.py:300: TracerWarning: Converting a tensor to a Python index 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!
len(proposals) for proposals in proposal_list)
/data/hbchen/mmdetection/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)
/data/hbchen/mmdetection/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
/data/hbchen/mmdetection/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:
Traceback (most recent call last):
File "tools/deployment/pytorch2onnx.py", line 275, in <module>
dynamic_export=args.dynamic_export)
File "tools/deployment/pytorch2onnx.py", line 77, in pytorch2onnx
dynamic_axes=dynamic_axes)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/onnx/init.py", line 143, in export
strip_doc_string, dynamic_axes, keep_initializers_as_inputs)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/onnx/utils.py", line 66, in export
dynamic_axes=dynamic_axes, keep_initializers_as_inputs=keep_initializers_as_inputs)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/onnx/utils.py", line 382, in _export
fixed_batch_size=fixed_batch_size)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/onnx/utils.py", line 249, in _model_to_graph
graph, torch_out = _trace_and_get_graph_from_model(model, args, training)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/onnx/utils.py", line 206, in _trace_and_get_graph_from_model
trace, torch_out, inputs_states = torch.jit.get_trace_graph(model, args, _force_outplace=True, _return_inputs_states=True)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/jit/init.py", line 275, in get_trace_graph
return LegacyTracedModule(f, _force_outplace, return_inputs, _return_inputs_states)(*args, kwargs)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, kwargs)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/jit/init.py", line 352, in forward
out = self.inner(trace_inputs)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/nn/modules/module.py", line 539, in call
result = self._slow_forward(input, kwargs)
File "/home/omnisky/anaconda3/envs/hbchen/lib/python3.7/site-packages/torch/nn/modules/module.py", line 525, in _slow_forward
result = self.forward(*input, kwargs)
File "/data/hbchen/mmcv/mmcv/runner/fp16_utils.py", line 95, in new_func
return old_func(*args, kwargs)
File "/data/hbchen/mmdetection/mmdet/models/detectors/base.py", line 169, in forward
return self.forward_test(img, img_metas, kwargs)
File "/data/hbchen/mmdetection/mmdet/models/detectors/base.py", line 146, in forward_test
return self.simple_test(imgs[0], img_metas[0], kwargs)
File "/data/hbchen/mmdetection/mmdet/models/detectors/two_stage.py", line 183, in simple_test
x, proposal_list, img_metas, rescale=rescale)
File "/data/hbchen/mmdetection/mmdet/models/roi_heads/cascade_roi_head.py", line 316, in simple_test
for j in range(num_imgs)
File "/data/hbchen/mmdetection/mmdet/models/roi_heads/cascade_roi_head.py", line 316, in <listcomp>
for j in range(num_imgs)
File "/data/hbchen/mmcv/mmcv/runner/fp16_utils.py", line 182, in new_func
return old_func(*args, *kwargs)
File "/data/hbchen/mmdetection/mmdet/models/roi_heads/bbox_heads/bbox_head.py", line 524, in regress_by_class
rois[:, 1:], bbox_pred, max_shape=img_meta['img_shape'])
File "/data/hbchen/mmdetection/mmdet/core/bbox/coder/delta_xywh_bbox_coder.py", line 92, in decode
self.add_ctr_clamp, self.ctr_clamp)
File "/data/hbchen/mmcv/mmcv/utils/parrots_jit.py", line 21, in wrapper_inner
return func(args, kargs)
File "/data/hbchen/mmdetection/mmdet/core/bbox/coder/delta_xywh_bbox_coder.py", line 254, in delta2bbox
x1, y1, x2, y2 = dynamic_clip_for_onnx(x1, y1, x2, y2, max_shape)
File "/data/hbchen/mmdetection/mmdet/core/export/onnx_helper.py", line 23, in dynamic_clip_for_onnx
torch.Tensor), 'max_shape
should be tensor of (h,w) for onnx'
AssertionError: max_shape
should be tensor of (h,w) for onnx
------------------ 原始邮件 ------------------
发件人: @.>;
发送时间: 2021年5月8日(星期六) 下午2:07
收件人: @.>;
抄送: @.>; @.>;
主题: Re: [open-mmlab/mmdetection] pytorch2onnx.py: AssertionError: max_shape
should be tensor of (h,w) for onnx (#5125)
@hbchen-hf Hi, could you provide detailed info about this issue?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@hbchen-hf Hi, we do not support cascade_rcnn model for exporting to ONNX by far. You could refer to the doc. https://github.com/open-mmlab/mmdetection/blob/master/docs/tutorials/pytorch2onnx.md#list-of-supported-models-exportable-to-onnx
AssertionError:
max_shape
should be tensor of (h,w) for onnx