[Enhancement] Remove batch inference assertion (#3210)
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers. ## Motivation https://github.com/open-mmlab/mmsegmentation/issues/3181 https://github.com/open-mmlab/mmsegmentation/issues/2965 https://github.com/open-mmlab/mmsegmentation/issues/2644 https://github.com/open-mmlab/mmsegmentation/issues/1645 https://github.com/open-mmlab/mmsegmentation/issues/1444 https://github.com/open-mmlab/mmsegmentation/issues/1370 https://github.com/open-mmlab/mmsegmentation/issues/125 ## Modification Remove the assertion at data_preprocessor ## BC-breaking (Optional) Does the modification introduce changes that break the backward-compatibility of the downstream repos? If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR. ## Use cases (Optional) If this PR introduces a new feature, it is better to list some use cases here, and update the documentation. ## Checklist 1. Pre-commit or other linting tools are used to fix the potential lint issues. 2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. 3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. 4. The documentation has been modified accordingly, like docstring or example tutorials.pull/3223/head
parent
20fa12912f
commit
857f854b61
|
@ -132,9 +132,9 @@ class SegDataPreProcessor(BaseDataPreprocessor):
|
||||||
inputs, data_samples = self.batch_augments(
|
inputs, data_samples = self.batch_augments(
|
||||||
inputs, data_samples)
|
inputs, data_samples)
|
||||||
else:
|
else:
|
||||||
assert len(inputs) == 1, (
|
img_size = inputs[0].shape[1:]
|
||||||
'Batch inference is not support currently, '
|
assert all(input_.shape[1:] == img_size for input_ in inputs), \
|
||||||
'as the image size might be different in a batch')
|
'The image size in a batch should be the same.'
|
||||||
# pad images when testing
|
# pad images when testing
|
||||||
if self.test_cfg:
|
if self.test_cfg:
|
||||||
inputs, padded_samples = stack_batch(
|
inputs, padded_samples = stack_batch(
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
# Copyright (c) OpenMMLab. All rights reserved.
|
# Copyright (c) OpenMMLab. All rights reserved.
|
||||||
|
import logging
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import torch.nn as nn
|
import torch.nn as nn
|
||||||
import torch.nn.functional as F
|
import torch.nn.functional as F
|
||||||
|
from mmengine.logging import print_log
|
||||||
from torch import Tensor
|
from torch import Tensor
|
||||||
|
|
||||||
from mmseg.registry import MODELS
|
from mmseg.registry import MODELS
|
||||||
|
@ -330,7 +332,11 @@ class EncoderDecoder(BaseSegmentor):
|
||||||
f'Only "slide" or "whole" test mode are supported, but got ' \
|
f'Only "slide" or "whole" test mode are supported, but got ' \
|
||||||
f'{self.test_cfg["mode"]}.'
|
f'{self.test_cfg["mode"]}.'
|
||||||
ori_shape = batch_img_metas[0]['ori_shape']
|
ori_shape = batch_img_metas[0]['ori_shape']
|
||||||
assert all(_['ori_shape'] == ori_shape for _ in batch_img_metas)
|
if not all(_['ori_shape'] == ori_shape for _ in batch_img_metas):
|
||||||
|
print_log(
|
||||||
|
'Image shapes are different in the batch.',
|
||||||
|
logger='current',
|
||||||
|
level=logging.WARN)
|
||||||
if self.test_cfg.mode == 'slide':
|
if self.test_cfg.mode == 'slide':
|
||||||
seg_logit = self.slide_inference(inputs, batch_img_metas)
|
seg_logit = self.slide_inference(inputs, batch_img_metas)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue