fix mmseg twice resize (#480)

* fix mmseg twich resize

* remove comment
pull/538/head
RunningLeon 2022-05-25 09:52:42 +08:00 committed by GitHub
parent d16720b127
commit 4f49763c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 15 deletions

View File

@ -1,9 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.
import torch.nn.functional as F
from mmseg.ops import resize
from mmdeploy.core import FUNCTION_REWRITER
from mmdeploy.utils import is_dynamic_shape
@FUNCTION_REWRITER.register_rewriter(
@ -25,16 +23,6 @@ def encoder_decoder__simple_test(ctx, self, img, img_meta, **kwargs):
torch.Tensor: Output segmentation map pf shape [N, 1, H, W].
"""
seg_logit = self.encode_decode(img, img_meta)
seg_logit = resize(
input=seg_logit,
size=img_meta['img_shape'],
mode='bilinear',
align_corners=self.align_corners)
seg_logit = F.softmax(seg_logit, dim=1)
seg_pred = seg_logit.argmax(dim=1)
# our inference backend only support 4D output
shape = seg_pred.shape
if not is_dynamic_shape(ctx.cfg):
shape = [int(_) for _ in shape]
seg_pred = seg_pred.view(shape[0], 1, shape[1], shape[2])
seg_pred = seg_logit.argmax(dim=1, keepdim=True)
return seg_pred

View File

@ -93,7 +93,8 @@ def _demo_mm_inputs(input_shape=(1, 3, 8, 16), num_classes=10):
return mm_inputs
@pytest.mark.parametrize('backend', [Backend.ONNXRUNTIME, Backend.OPENVINO])
@pytest.mark.parametrize('backend',
[Backend.ONNXRUNTIME, Backend.OPENVINO, Backend.NCNN])
def test_encoderdecoder_simple_test(backend):
check_backend(backend)
segmentor = get_model()
@ -109,7 +110,8 @@ def test_encoderdecoder_simple_test(backend):
num_classes = segmentor.decode_head[-1].num_classes
else:
num_classes = segmentor.decode_head.num_classes
mm_inputs = _demo_mm_inputs(num_classes=num_classes)
mm_inputs = _demo_mm_inputs(
input_shape=(1, 3, 32, 32), num_classes=num_classes)
imgs = mm_inputs.pop('imgs')
img_metas = mm_inputs.pop('img_metas')
model_inputs = {'img': imgs, 'img_meta': img_metas}