Closed
Description
Describe the bug
For some models, it is possible to specify out_indices
that are not viable. Instead of failing, the create_model
function returns a model with the non-viable indices missing.
To Reproduce
Steps to reproduce the behavior:
import torch
from timm import create_model
model = create_model(
"deit3_base_patch16_224.fb_in22k_ft_in1k",
pretrained=True,
exportable=True,
in_chans=1,
out_indices=[3, 5, 7, 100],
features_only=True,
)
shape = (1, 1, 224, 224)
input_ = torch.randn(shape)
output_ = model(input_)
for feature in output_:
print(f"{feature.shape=}")
feature.shape=torch.Size([1, 768, 14, 14])
feature.shape=torch.Size([1, 768, 14, 14])
feature.shape=torch.Size([1, 768, 14, 14])
Expected behavior
If not an error, at least a warning that some indices that where specified will be ignored.
Desktop (please complete the following information):
- Platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
- Python version: 3.10.14
- PyTorch version (GPU?): 2.3.1+cu121 (False)
- timm version: 1.0.7
Incorrectly working models
- deit3_base_patch16_224.fb_in22k_ft_in1k
- eva02_base_patch14_224.mim_in22k
Correctly? working models
- tf_efficientnet_b7.ns_jft_in1k
Traceback (most recent call last):
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/minimal_example.py", line 4, in <module>
model = create_model(
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/_factory.py", line 117, in create_model
model = create_fn(
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/efficientnet.py", line 2307, in tf_efficientnet_b7
model = _gen_efficientnet(
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/efficientnet.py", line 651, in _gen_efficientnet
model = _create_effnet(variant, pretrained, **model_kwargs)
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/efficientnet.py", line 368, in _create_effnet
model = build_model_with_cfg(
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/_builder.py", line 406, in build_model_with_cfg
model = model_cls(**kwargs)
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/efficientnet.py", line 321, in __init__
self._stage_out_idx = {f['stage']: f['index'] for f in self.feature_info.get_dicts()}
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/_features.py", line 120, in get_dicts
return [self.info[i] for i in self.out_indices]
File "/mnt/c/Users/fuchsfa/Desktop/Git/foundation-models/.venv/lib/python3.10/site-packages/timm/models/_features.py", line 120, in <listcomp>
return [self.info[i] for i in self.out_indices]
IndexError: list index out of range
Not sure if this is by design or accident, but EfficentNet throws an error.