pytorch-image-models icon indicating copy to clipboard operation
pytorch-image-models copied to clipboard

[BUG] feature_info.channels() is not match

Open brianhou0208 opened this issue 11 months ago • 1 comments

Describe the bug These models return feature_info.channels() is not match

  • ecaresnet50d_pruned
  • ecaresnet101d_pruned
  • efficientnet_b1_pruned
  • efficientnet_b2_pruned
  • efficientnet_b3_pruned

To Reproduce

import timm
import torch

model_list = [
    ["ecaresnet50d_pruned", 224],
    ["ecaresnet101d_pruned", 224],
    ["efficientnet_b1_pruned", 224],
    ["efficientnet_b2_pruned", 224],
    ["efficientnet_b3_pruned", 224]
]

if __name__ == "__main__":
    for model_name, img_size in model_list:
        x = torch.rand(1, 3, 224, 224)
        model = timm.create_model(f"{model_name}", features_only=True).eval()
        y = model(x)
        print(model_name)
        print(f"    Feature shape: {[f.detach().numpy().shape[1:] for f in y]}")
        print(f"    Feature channels: {model.feature_info.channels()}")
        print()
ecaresnet50d_pruned
    Feature shape: [(64, 112, 112), (19, 56, 56), (171, 28, 28), (818, 14, 14), (2022, 7, 7)]
    Feature channels: [64, 256, 512, 1024, 2048]

ecaresnet101d_pruned
    Feature shape: [(64, 112, 112), (26, 56, 56), (142, 28, 28), (278, 14, 14), (2042, 7, 7)]
    Feature channels: [64, 256, 512, 1024, 2048]

efficientnet_b1_pruned
    Feature shape: [(16, 112, 112), (12, 56, 56), (35, 28, 28), (67, 14, 14), (320, 7, 7)]
    Feature channels: [16, 24, 40, 112, 320]

efficientnet_b2_pruned
    Feature shape: [(16, 112, 112), (17, 56, 56), (42, 28, 28), (116, 14, 14), (352, 7, 7)]
    Feature channels: [16, 24, 48, 120, 352]

efficientnet_b3_pruned
    Feature shape: [(24, 112, 112), (12, 56, 56), (40, 28, 28), (120, 14, 14), (384, 7, 7)]
    Feature channels: [24, 32, 48, 136, 384]

Expected behavior

  • ecaresnet50d_pruned feature channels (64, 19, 171, 818, 2022)
  • ecaresnet101d_pruned feature channels (64, 26, 142, 278, 2042)
  • efficientnet_b1_pruned feature channels (16, 12, 35, 67, 320)
  • efficientnet_b2_pruned feature channels (16, 17, 42, 116, 352)
  • efficientnet_b3_pruned feature channels (24, 12, 40, 120, 384)

brianhou0208 avatar Dec 18 '24 17:12 brianhou0208

@brianhou0208 known issue, along with #1597 ... don't really have a good way to handle the channel count changes in these pruned models, I feel it'd be quite a bit of work to do cleanly. If you see a clean path to a good soln, PR are welcome, there might be some way to make the pruning process aware of / able to modify the info....

rwightman avatar Dec 18 '24 20:12 rwightman