Install & Compatibility
Where this runs
tested against v1.0.28 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.10
✕ build_error
✓ 72.9s
py 3.11
✕ build_error
✓ 70.4s
py 3.12
✕ build_error
✓ 59.6s
py 3.13
✕ build_error
✓ 61.4s
py 3.9
✕ build_error
✕ timeout
4890MB installed
● package 4890MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
timm.layers
✓ from timm.layers import PatchEmbed, Mlp, DropPath
# or
import timm.layers
✗ from timm.models.layers import PatchEmbed, Mlp, DropPath # moved in 0.9 — deprecated mapping exists but will be removed
timm.models.layers was moved to timm.layers in 0.9.x. Direct module imports like import timm.models.layers.module no longer work — only the top-level from timm.models.layers import name still works via a deprecation shim.
create_model
✓ import timm
# Load with pretrained weights
model = timm.create_model('resnet50', pretrained=True)
# Load specific weight variant using architecture.tag format
model = timm.create_model('resnet50.a1_in1k', pretrained=True)
# Custom num_classes for fine-tuning
model = timm.create_model('efficientnet_b0', pretrained=True, num_classes=10)
# Feature extraction (removes classifier)
model = timm.create_model('resnet50', features_only=True, pretrained=True)
✗ # Old-style weight loading from GitHub releases (no longer primary source)
model = timm.create_model('resnet50', pretrained=True)
# Weights now come from HF Hub: https://huggingface.co/timm
Pretrained weights now load from Hugging Face Hub (huggingface.co/timm) not GitHub releases. Model names with architecture.pretrained_tag (e.g. resnet50.a1_in1k) select specific weight variants.
Load pretrained model, apply model-specific preprocessing, run inference.
import timm
import torch
from PIL import Image
from timm.data import resolve_data_config, create_transform
# List available models
print(timm.list_models('resnet*')[:5])
# Load pretrained model
model = timm.create_model('efficientnet_b0.ra_in1k', pretrained=True)
model.eval()
# Get model-specific preprocessing
config = resolve_data_config({}, model=model)
transform = create_transform(**config)
# Inference
img = Image.open('image.jpg').convert('RGB')
tensor = transform(img).unsqueeze(0)
with torch.no_grad():
output = model(tensor) # [1, 1000] logits
probs = torch.softmax(output, dim=1)
top5 = torch.topk(probs, 5)
# Fine-tune with custom head
model = timm.create_model('resnet50', pretrained=True, num_classes=10)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'timm.models.layers'
The import path for utility layers in `timm` changed from `timm.models.layers` to `timm.layers` starting from version 0.10.0 (and is present in 1.0.15).
fixReplace `from timm.models.layers import ...` with `from timm.layers import ...`.
OSError: Specified pretrained weights did not exist for model 'model_name'. Check your entry and try again.
The model name provided to `timm.create_model` might be incorrect, there could be network issues preventing download from Hugging Face Hub, or the specified model does not have pretrained weights available.
fixVerify the model name against `timm.list_models(pretrained=True)`, ensure an active internet connection, and check if the model actually supports pretrained weights.
RuntimeError: Expected 4D input for conv2d, got 3D input instead
The input tensor provided to the model's `forward` method is missing the expected batch dimension. `timm` models typically expect input in `[batch_size, channels, height, width]` format.
fixAdd a batch dimension to your input tensor, typically by using `input_tensor.unsqueeze(0)` for a single image.
AttributeError: 'ResNet' object has no attribute 'fc' (or 'EfficientNet' object has no attribute 'classifier')
The name of the final classification layer (or head) varies across different `timm` models and architectures. Common names include `head`, `fc`, or `classifier`.
fixInspect the model's structure (e.g., `print(model)`) to identify the correct attribute name for the classification head, which is often `model.head` for many `timm` models.
Upgrade
Version history
1.0.28latest on PyPI · released Jul 11, 2026
Audit
Dependencies
torch>=1.7requiredRequired. Install PyTorch separately first — timm does not pin a specific version.
torchvisionrequiredRequired. Installed automatically.
huggingface-hubrequiredRequired for loading weights from HF Hub (default since 0.9). Installed automatically.
safetensorsrequiredRequired for safetensors weight format. Installed automatically.