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

[Bugfix] test resize with pad_shape #3421

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion mmseg/models/decode_heads/decode_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,17 @@ def predict_by_feat(self, seg_logits: Tensor,
Tensor: Outputs segmentation logits map.
"""

if isinstance(batch_img_metas[0]['img_shape'], torch.Size):
# slide inference
size = batch_img_metas[0]['img_shape']
elif 'pad_shape' in batch_img_metas[0]:
size = batch_img_metas[0]['pad_shape'][:2]
else:
size = batch_img_metas[0]['img_shape']

seg_logits = resize(
input=seg_logits,
size=batch_img_metas[0]['img_shape'],
size=size,
mode='bilinear',
align_corners=self.align_corners)
return seg_logits
7 changes: 5 additions & 2 deletions mmseg/models/decode_heads/san_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ def predict_by_feat(self, seg_logits: List[Tensor],
"""
mask_pred = seg_logits[0]
cls_score = seg_logits[1]
if 'pad_shape' in batch_img_metas[0]:
size = batch_img_metas[0]['pad_shape']
if isinstance(batch_img_metas[0]['img_shape'], torch.Size):
# slide inference
size = batch_img_metas[0]['img_shape']
elif 'pad_shape' in batch_img_metas[0]:
size = batch_img_metas[0]['pad_shape'][:2]
else:
size = batch_img_metas[0]['img_shape']
# upsample mask
Expand Down
9 changes: 8 additions & 1 deletion projects/hssn/decode_head/sep_aspp_contrast_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,17 @@ def predict_by_feat(self, seg_logits: Tuple[Tensor],
# elif seg_logit.size(1) == 144 # For Mapillary dataset, 124+16+4
# unofficial repository not release mapillary until 2023/2/6

if isinstance(batch_img_metas[0]['img_shape'], torch.Size):
# slide inference
size = batch_img_metas[0]['img_shape']
elif 'pad_shape' in batch_img_metas[0]:
size = batch_img_metas[0]['pad_shape'][:2]
else:
size = batch_img_metas[0]['img_shape']
seg_logit = seg_logit[:, :-hiera_num_classes]
seg_logit = resize(
input=seg_logit,
size=batch_img_metas[0]['img_shape'],
size=size,
mode='bilinear',
align_corners=self.align_corners)

Expand Down