Skip to content

Conversation

@brianhou0208
Copy link
Contributor

Hi @rwightman ,

This PR fix feature_info.reduction for:

  • MetaFormer (CaFormer, ConvFormer, PoolFormer, PoolFormerV2)
  • DaViT
  • EfficientFormer

Test code

import timm import torch model_list = [ ["caformer_s18", 224], ["convformer_s18", 224], ["poolformer_s12", 224], ["poolformerv2_s12", 224], ["davit_tiny", 224], ["efficientformer_l1", 224] ] if __name__ == "__main__": for model_name, img_size in model_list: x = torch.rand(1, 3, img_size, img_size) model = timm.create_model(f"{model_name}", features_only=True).eval() y = model(x) print(f"timm-{model_name}-(C, H, W) = {(3, img_size, img_size)}") print(f" Feature shape: {[f.detach().numpy().shape[1:] for f in y]}") print(f" Feature channels: {model.feature_info.channels()}") print(f" Feature reduction: {model.feature_info.reduction()}")

Before this PR

self.feature_info += [dict(num_chs=dims[i], reduction=2, module=f'stages.{i}')]

Output

timm-caformer_s18-(C, H, W) = (3, 224, 224) Feature shape: [(64, 56, 56), (128, 28, 28), (320, 14, 14), (512, 7, 7)] Feature channels: [64, 128, 320, 512] Feature reduction: [2, 2, 2, 2]

After this PR

self.feature_info += [dict(num_chs=dims[i], reduction=2**(i+2), module=f'stages.{i}')]

Output

timm-caformer_s18-(C, H, W) = (3, 224, 224) Feature shape: [(64, 56, 56), (128, 28, 28), (320, 14, 14), (512, 7, 7)] Feature channels: [64, 128, 320, 512] Feature reduction: [4, 8, 16, 32]
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@rwightman rwightman merged commit a02b1a8 into huggingface:main Dec 19, 2024
22 checks passed
@brianhou0208 brianhou0208 deleted the fix_reduction branch December 19, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants