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

[Enhancement] Support padding in testing #2290

Merged
merged 6 commits into from
Nov 19, 2022

Conversation

xiexinch
Copy link
Collaborator

@xiexinch xiexinch commented Nov 10, 2022

Motivation

  • Fix removing gt_sem_seg padding at postprocess_result
  • Support different padding methods in testing

Modification

  • Add removing gt_sem_seg padding at postprocess_result method in mmseg/models/segmentors/base.py.
  • Add test_cfg` params to SegDataPreprocessor, supporting different padding methods.

BC-breaking (Optional)

None

Use cases

In a case that uses size in training and using size_divisor in testing, we might set the test_cfg param to data_preprocessor.

data_preprocessor = dict(
    type='SegDataPreProcessor',
    mean=[123.675, 116.28, 103.53],
    std=[58.395, 57.12, 57.375],
    bgr_to_rgb=True,
    pad_val=0,
    seg_pad_val=255,
    size=(512, 512),
    test_cfg=dict(size_divisor=32))

@xiexinch xiexinch added the 1.x Related issue of 1.x version label Nov 10, 2022
Copy link
Collaborator

@MeowZheng MeowZheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add ut for the new function

Comment on lines 51 to 56
train_cfg (dict, optional): The padding size config in training, if
not specify, will use `size` and `size_divisor` params as default.
Defaults to None, only supports keys `size` or `size_divisor`.
test_cfg (dict, optional): The padding size config in testing, if not
specify, will use `size` and `size_divisor` params as default.
Defaults to None, only supports keys `size` or `size_divisor`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an example in PR description for train_cfg and test_cfg as a padding config for input data.

@codecov
Copy link

codecov bot commented Nov 10, 2022

Codecov Report

Base: 83.57% // Head: 83.65% // Increases project coverage by +0.08% 🎉

Coverage data is based on head (8fed7f5) compared to base (38c3145).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head 8fed7f5 differs from pull request most recent head 4e12bcd. Consider uploading reports for the commit 4e12bcd to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x    #2290      +/-   ##
===========================================
+ Coverage    83.57%   83.65%   +0.08%     
===========================================
  Files          141      141              
  Lines         7970     7974       +4     
  Branches      1192     1193       +1     
===========================================
+ Hits          6661     6671      +10     
+ Misses        1119     1114       -5     
+ Partials       190      189       -1     
Flag Coverage Δ
unittests 83.65% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/models/data_preprocessor.py 93.02% <100.00%> (+0.52%) ⬆️
mmseg/models/segmentors/base.py 87.50% <100.00%> (+0.19%) ⬆️
mmseg/utils/misc.py 90.90% <0.00%> (+13.63%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@MeowZheng MeowZheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please try to use Pad in test pipeline

@MeowZheng MeowZheng added this to the 1.0.0rc2 milestone Nov 11, 2022
@xiexinch
Copy link
Collaborator Author

please try to use Pad in test pipeline

If use Pad in test _pipeline, the padded pixels would be normalized.
https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/mmseg/models/data_preprocessor.py#L108

@xiexinch xiexinch changed the title [Enhancement] Support different padding methods in training and testing [Enhancement] Support different padding in testing Nov 17, 2022
@xiexinch xiexinch changed the title [Enhancement] Support different padding in testing [Enhancement] Support padding in testing Nov 17, 2022
Comment on lines 140 to 146
inputs, data_samples = stack_batch(
inputs=inputs,
data_samples=data_samples,
size=self.test_cfg.get('size', None),
size_divisor=self.test_cfg.get('size_divisor', None),
pad_val=self.pad_val,
seg_pad_val=self.seg_pad_val)
Copy link
Collaborator

@MeowZheng MeowZheng Nov 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inputs, data_samples = stack_batch(
inputs=inputs,
data_samples=data_samples,
size=self.test_cfg.get('size', None),
size_divisor=self.test_cfg.get('size_divisor', None),
pad_val=self.pad_val,
seg_pad_val=self.seg_pad_val)
inputs, data_samples = stack_batch(
inputs=inputs,
size=self.test_cfg.get('size', None),
size_divisor=self.test_cfg.get('size_divisor', None),
pad_val=self.pad_val,
seg_pad_val=self.seg_pad_val)

I think it would be better to keep gt as original when model testing or validation.

Comment on lines 168 to 173
i_gt_sem_seg = data_samples[i].gt_sem_seg.data[:,
padding_top:H -
padding_bottom,
padding_left:W -
padding_right]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
i_gt_sem_seg = data_samples[i].gt_sem_seg.data[:,
padding_top:H -
padding_bottom,
padding_left:W -
padding_right]

Comment on lines 194 to 195
'gt_sem_seg':
PixelData() if only_prediction else PixelData(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to add an empty PixelData for gt_sem_seg when only predict?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@MeowZheng MeowZheng merged commit c56a299 into open-mmlab:dev-1.x Nov 19, 2022
MeowZheng pushed a commit to MeowZheng/mmsegmentation that referenced this pull request Dec 30, 2022
* support padding in test and fix remove gt padding at post_process

* fix get gt data

* fix ut

* add data_preprocessor ut

* remove gt padding

* fix data sample is None
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
wjkim81 pushed a commit to wjkim81/mmsegmentation that referenced this pull request Dec 3, 2023
nahidnazifi87 pushed a commit to nahidnazifi87/mmsegmentation_playground that referenced this pull request Apr 5, 2024
[Enhancement] Support padding in testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Related issue of 1.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants