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

[Feature] Add TTA transform #2146

Merged
merged 11 commits into from
Oct 19, 2022
Merged

[Feature] Add TTA transform #2146

merged 11 commits into from
Oct 19, 2022

Conversation

HAOCHENYE
Copy link
Collaborator

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

Transforms used by test time augmentation.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the back-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)

transforms = [
    [dict(type='Resize', scale=(1333, 800), keep_ratio=True),
     dict(type='Resize', scale=(1333, 800), keep_ratio=True)], 
    [dict(type='RandomFlip', prob=1.),
     dict(type='RandomFlip', prob=0.)], 
    [dict(type='Normalize', mean=(0, 0, 0), std=(1, 1, 1))]]

tta_transform = TestTimeAug(transforms)

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 MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@zhouzaida zhouzaida requested review from mzr1996 and ly015 July 26, 2022 15:29
@ZwwWayne ZwwWayne added this to the 2.0.0rc2 milestone Aug 15, 2022
@mzr1996
Copy link
Member

mzr1996 commented Sep 13, 2022

Maybe use a cartesian product to implement the subroutines

from itertools import product

@TRANSFORMS.register_module()
class TestTimeAug(BaseTransform):

    def __init__(self, transforms: list):
        self.subroutines = [Compose(subroutine) for subroutine in product(*transfroms)]

    def transform(self, results: dict) -> dict:
        results_list = []  # type: ignore
        for subroutine in self.subroutines:
            routine_results = subroutine(deepcopy(results))
            results_list.append(routine_results)

        aug_data_dict = {
            key: [item[key] for item in results]
            for key in results_list[0]
        }
        return aug_data_dict

@zhouzaida zhouzaida changed the base branch from dev-2.x to 2.x September 14, 2022 08:54
@zhouzaida zhouzaida added the 2.x label Oct 16, 2022
Co-authored-by: Zaida Zhou <[email protected]>
@zhouzaida zhouzaida merged commit a6c42ad into open-mmlab:2.x Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants