Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix roi align symbolic function in onnx opset>=16 #2428

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions mmdeploy/mmcv/ops/roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,38 @@
else:
from torch.onnx.symbolic_opset9 import _cast_Long
from torch.onnx.symbolic_opset11 import add, select
batch_indices = _cast_Long(
g,
g.op(
'Squeeze',
select(
g, rois, 1,
g.op(
'Constant',
value_t=torch.tensor([0], dtype=torch.long))),
axes_i=[1]), False)
ir_cfg = get_ir_config(ctx.cfg)
opset_version = ir_cfg.get('opset_version', 11)
if opset_version < 13:
batch_indices = _cast_Long(
g,
g.op(
'Squeeze',
select(
g, rois, 1,
g.op(
'Constant',
value_t=torch.tensor([0], dtype=torch.long))),
axes_i=[1]), False)
else:
axes = g.op(

Check warning on line 75 in mmdeploy/mmcv/ops/roi_align.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/mmcv/ops/roi_align.py#L75

Added line #L75 was not covered by tests
'Constant', value_t=torch.tensor([1], dtype=torch.long))
batch_indices = _cast_Long(

Check warning on line 77 in mmdeploy/mmcv/ops/roi_align.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/mmcv/ops/roi_align.py#L77

Added line #L77 was not covered by tests
g,
g.op(
'Squeeze',
select(
g, rois, 1,
g.op(
'Constant',
value_t=torch.tensor([0], dtype=torch.long))),
axes), False)
rois = select(
g, rois, 1,
g.op(
'Constant',
value_t=torch.tensor([1, 2, 3, 4], dtype=torch.long)))
ir_cfg = get_ir_config(ctx.cfg)
opset_version = ir_cfg.get('opset_version', 11)

if opset_version < 16:
# preprocess rois to make compatible with opset 16-
# as for opset 16+, `aligned` get implemented inside onnxruntime.
Expand All @@ -96,6 +111,10 @@
sampling_ratio_i=sampling_ratio,
mode_s=pool_mode)
else:
if aligned:
coordinate_transformation_mode = 'half_pixel'

Check warning on line 115 in mmdeploy/mmcv/ops/roi_align.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/mmcv/ops/roi_align.py#L115

Added line #L115 was not covered by tests
else:
coordinate_transformation_mode = 'output_half_pixel'

Check warning on line 117 in mmdeploy/mmcv/ops/roi_align.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/mmcv/ops/roi_align.py#L117

Added line #L117 was not covered by tests
return g.op(
'RoiAlign',
input,
Expand All @@ -106,4 +125,5 @@
spatial_scale_f=spatial_scale,
sampling_ratio_i=sampling_ratio,
mode_s=pool_mode,
aligned_i=aligned)
coordinate_transformation_mode_s=coordinate_transformation_mode
)
Loading