[Fix] Fix ResizeToMultiple transform in MMSeg 1.x (#2185)

pull/2202/head
MengzhangLI 2022-10-14 15:37:35 +08:00 committed by GitHub
parent 84e76492b9
commit f3cd44bebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 17 deletions

View File

@ -77,20 +77,13 @@ using `AlignedResize`, you can change the dataset pipeline like this:
```python
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(
type='MultiScaleFlipAug',
img_scale=(2048, 512),
# img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75],
flip=False,
transforms=[
dict(type='Resize', keep_ratio=True),
# resize image to multiple of 32, improve SegFormer by 0.5-1.0 mIoU.
dict(type='ResizeToMultiple', size_divisor=32),
dict(type='RandomFlip'),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img']),
])
dict(type='Resize', scale=(2048, 512), keep_ratio=True),
# resize image to multiple of 32, improve SegFormer by 0.5-1.0 mIoU.
dict(type='ResizeToMultiple', size_divisor=32),
# add loading annotation after ``Resize`` because ground truth
# does not need to do resize data transform
dict(type='LoadAnnotations', reduce_zero_label=True),
dict(type='PackSegInputs')
]
```

View File

@ -59,8 +59,8 @@ class ResizeToMultiple(BaseTransform):
if self.interpolation else 'bilinear')
results['img'] = img
results['img_shape'] = img.shape
results['pad_shape'] = img.shape
results['img_shape'] = img.shape[:2]
results['pad_shape'] = img.shape[:2]
# Align segmentation map to multiple of size divisor.
for key in results.get('seg_fields', []):

View File

@ -678,4 +678,4 @@ def test_resize_to_multiple():
results = transform(results)
assert results['img'].shape == (224, 256, 3)
assert results['gt_semantic_seg'].shape == (224, 256)
assert results['img_shape'] == (224, 256, 3)
assert results['img_shape'] == (224, 256)