huggingface / pytorch-image-models

The largest collection of PyTorch image encoders / backbones. Including train, eval, inference, export scripts, and pretrained weights -- ResNet, ResNeXT, EfficientNet, NFNet, Vision Transformer (ViT), MobileNetV4, MobileNet-V3 & V2, RegNet, DPN, CSPNet, Swin Transformer, MaxViT, CoAtNet, ConvNeXt, and more
https://huggingface.co/docs/timm
Apache License 2.0
31.47k stars 4.7k forks source link

[BUG] Issue title... out_indices feature messed up in nf_resnet50 #471

Closed code-demoe closed 3 years ago

code-demoe commented 3 years ago

nf_resnet50 does not work well with out_indices parameter

  1. the out_indices does not accept inputs starting from 0 like: out_indices=(0,1,2) will throw an error
  2. the model.feature_info.channels() does not match the indexing
  3. the output of feature extractor is a list of size 1 less than mentioned in the out_indices feature
  4. the channels start from 256 rather than 64

To Reproduce Steps to reproduce the behavior: 1.try: model=timm.create_model('nf_resnet50', features_only=True, out_indices=(0,1)) gives error: Return layers ({'': 'forward'}) are not present in model 2.but model=timm.create_model('nf_resnet50', features_only=True, out_indices=(1,2)) works, but with mismatched model and channel indices

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

rwightman commented 3 years ago

@code-demoe there is no idx 0 feature for nf_resnet in the current impl, I was grabbing only activated features and there is no activation btw the stride 2 opening conv and the stride 2 max pool so that's expected. I've actually decided to change that and just return non-activation features for pre-activation nets like the NFNets and ResNetV2 so these nets won't be special case anymore. Hoping to push that in the next few days.

The mismatch is a bug as the channels should have respected the 1, 2 indices.

code-demoe commented 3 years ago

Thanks for the amazing library though. Also InplaceABN is giving error during installation, can you please look into them and if possible replace them with something more suitable. Many issues regarding installation are open on their github repo but none have been solved yet.

rwightman commented 3 years ago

@code-demoe try pip install git+https://github.com/mapillary/inplace_abn.git@v1.0.12 ... still working for me with pytorch 1.8, works with 1.7 and latest NGC containers, just updated the Github CI runner to use 1.8 and it also installs IABN. IABN dep isn't used unless a model with those defs is needed. If I remove it those models (like tresent) have to go too.

code-demoe commented 3 years ago

Thanks for the update. I realized it isn't working for conda environments only, as CUDA_HOME is not set for virtual environments using conda toolkits. If you know a workaround for conda please let me know.