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] Support EfficientFormer #954

Merged
merged 16 commits into from
Aug 16, 2022
Merged

Conversation

Ezra-Yu
Copy link
Collaborator

@Ezra-Yu Ezra-Yu commented Aug 4, 2022

Motivation

Support EfficientFormer, Arxiv | Github

Use cases (Optional)

    Example:
        >>> from mmcls.models import EfficientFormer
        >>> import torch
        >>> inputs = torch.rand((1, 3, 224, 224))
        >>> # build EfficientFormer backbone for classification task
        >>> model = EfficientFormer(arch="l1")
        >>> model.eval()
        >>> level_outputs = model(inputs)
        >>> for level_out in level_outputs:
        ...     print(tuple(level_out.shape))
        (1, 448, 49)
        >>> # build EfficientFormer backbone for downstream task
        >>> EfficientFormer(
        >>>    arch="l3",
        >>>    out_indices=(0, 1, 2, 3),
        >>>    reshape_last_feat=True)
        >>> model.eval()
        >>> level_outputs = model(inputs)
        >>> for level_out in level_outputs:
        ...     print(tuple(level_out.shape))

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@codecov
Copy link

codecov bot commented Aug 4, 2022

Codecov Report

Merging #954 (4dcea5a) into dev (b5bb86a) will increase coverage by 0.26%.
The diff coverage is 92.53%.

@@            Coverage Diff             @@
##              dev     #954      +/-   ##
==========================================
+ Coverage   85.86%   86.13%   +0.26%     
==========================================
  Files         136      140       +4     
  Lines        9306     9674     +368     
  Branches     1611     1677      +66     
==========================================
+ Hits         7991     8333     +342     
- Misses       1076     1090      +14     
- Partials      239      251      +12     
Flag Coverage Δ
unittests 86.06% <92.53%> (+0.27%) ⬆️

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

Impacted Files Coverage Δ
mmcls/datasets/voc.py 31.81% <28.57%> (-1.52%) ⬇️
mmcls/models/heads/efficientformer_head.py 92.10% <92.10%> (ø)
mmcls/models/heads/multi_label_csra_head.py 92.15% <92.15%> (ø)
mmcls/models/backbones/efficientformer.py 94.49% <94.49%> (ø)
mmcls/models/backbones/__init__.py 100.00% <100.00%> (ø)
mmcls/models/heads/__init__.py 100.00% <100.00%> (ø)
mmcls/datasets/__init__.py 100.00% <0.00%> (ø)
mmcls/models/backbones/regnet.py 98.05% <0.00%> (ø)
mmcls/datasets/stanford_cars.py 94.11% <0.00%> (ø)

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

@Ezra-Yu Ezra-Yu requested review from mzr1996 and tonysy August 5, 2022 03:03
mmcls/models/backbones/efficientformer.py Outdated Show resolved Hide resolved
mmcls/models/backbones/efficientformer.py Show resolved Hide resolved
if idx in self.out_indices:
norm_layer = getattr(self, f'norm{idx}')

if idx == len(self.network) - 1 and x.dim() == 3:
Copy link
Member

Choose a reason for hiding this comment

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

x.dim() == 3? why do we need this condition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in case the vit-num is 0 in arch.

mmcls/models/backbones/efficientformer.py Show resolved Hide resolved
mmcls/models/backbones/efficientformer.py Outdated Show resolved Hide resolved
Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@mzr1996 mzr1996 merged commit 6474ea2 into open-mmlab:dev Aug 16, 2022
Ezra-Yu added a commit to Ezra-Yu/mmclassification that referenced this pull request Sep 6, 2022
* add efficient backbone

* Update Readme and metafile

* Add unit tests

* fix confict

* fix lint

* update efficientformer head unit tests

* update README

* fix unit test

* fix Readme

* fix example

* fix typo

* recover api modification

* Update EfficiemtFormer Backbone

* fix unit tests

* add efficientformer to readme and model zoo
@Ezra-Yu Ezra-Yu deleted the effiFormer branch April 13, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants