{"id":218,"library":"timm","title":"timm","description":"PyTorch Image Models — collection of SOTA vision models, pretrained weights, layers, optimizers, and training utilities by Ross Wightman. Current version is 1.0.15 (Mar 2026). Primary weight source is now Hugging Face Hub. Import path for layers changed: timm.models.layers → timm.layers.","status":"active","version":"1.0.15","language":"python","source_language":"en","source_url":"https://huggingface.co/docs/hub/timm","tags":["computer-vision","image-classification","pretrained","resnet","efficientnet","vit","pytorch"],"install":[{"cmd":"pip install timm","lang":"bash","label":"Standard"}],"dependencies":[{"reason":"Required. Install PyTorch separately first — timm does not pin a specific version.","package":"torch>=1.7","optional":false},{"reason":"Required. Installed automatically.","package":"torchvision","optional":false},{"reason":"Required for loading weights from HF Hub (default since 0.9). Installed automatically.","package":"huggingface-hub","optional":false},{"reason":"Required for safetensors weight format. Installed automatically.","package":"safetensors","optional":false}],"imports":[{"note":"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.","wrong":"from timm.models.layers import PatchEmbed, Mlp, DropPath  # moved in 0.9 — deprecated mapping exists but will be removed","symbol":"timm.layers","correct":"from timm.layers import PatchEmbed, Mlp, DropPath\n# or\nimport timm.layers"},{"note":"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.","wrong":"# Old-style weight loading from GitHub releases (no longer primary source)\nmodel = timm.create_model('resnet50', pretrained=True)\n# Weights now come from HF Hub: https://huggingface.co/timm","symbol":"create_model","correct":"import timm\n\n# Load with pretrained weights\nmodel = timm.create_model('resnet50', pretrained=True)\n\n# Load specific weight variant using architecture.tag format\nmodel = timm.create_model('resnet50.a1_in1k', pretrained=True)\n\n# Custom num_classes for fine-tuning\nmodel = timm.create_model('efficientnet_b0', pretrained=True, num_classes=10)\n\n# Feature extraction (removes classifier)\nmodel = timm.create_model('resnet50', features_only=True, pretrained=True)"}],"quickstart":{"code":"import timm\nimport torch\nfrom PIL import Image\nfrom timm.data import resolve_data_config, create_transform\n\n# List available models\nprint(timm.list_models('resnet*')[:5])\n\n# Load pretrained model\nmodel = timm.create_model('efficientnet_b0.ra_in1k', pretrained=True)\nmodel.eval()\n\n# Get model-specific preprocessing\nconfig = resolve_data_config({}, model=model)\ntransform = create_transform(**config)\n\n# Inference\nimg = Image.open('image.jpg').convert('RGB')\ntensor = transform(img).unsqueeze(0)\n\nwith torch.no_grad():\n    output = model(tensor)          # [1, 1000] logits\n    probs = torch.softmax(output, dim=1)\n    top5 = torch.topk(probs, 5)\n\n# Fine-tune with custom head\nmodel = timm.create_model('resnet50', pretrained=True, num_classes=10)","lang":"python","description":"Load pretrained model, apply model-specific preprocessing, run inference."},"warnings":[{"fix":"Replace from timm.models.layers import X with from timm.layers import X throughout your codebase.","message":"timm.models.layers module moved to timm.layers in 0.9.x. Direct module imports (import timm.models.layers.module) fail. Only top-level from timm.models.layers import name still works via deprecation shim — which will be removed.","severity":"breaking","affected_versions":">= 0.9"},{"fix":"Use timm.list_models() to discover available model names. For specific weight variants use the architecture.tag format.","message":"Model naming changed to architecture.pretrained_tag format in 0.9+. Old names like resnet50_21k still work via deprecation remapping but new weight variants are only accessible via the new format (e.g. resnet50.a1_in1k).","severity":"breaking","affected_versions":">= 0.9"},{"fix":"Use timm.create_model(name, pretrained=True) — weight URLs are managed automatically. Do not hardcode weight URLs.","message":"Pretrained weights now loaded from Hugging Face Hub (https://huggingface.co/timm) not GitHub releases. Old GitHub release URLs hardcoded in custom code will 404.","severity":"breaking","affected_versions":">= 0.9"},{"fix":"For feature extraction: num_classes=0 (removes head). For fine-tuning with N classes: num_classes=N (replaces head with random init). Use model.reset_classifier(num_classes=N) to change after creation.","message":"timm.create_model with num_classes=0 removes the classifier entirely and returns features. num_classes=None is NOT the same — it keeps the default head. Setting wrong num_classes silently produces wrong output shapes.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use timm's preprocessing utilities: config = timm.data.resolve_data_config({}, model=model); transform = timm.data.create_transform(**config).","message":"Each model has its own expected preprocessing (mean, std, input size). Using generic ImageNet normalization values directly instead of model-specific config produces degraded accuracy.","severity":"gotcha","affected_versions":"all"},{"fix":"Use timm.list_models(pretrained=True) to list only models with available weights. Or check: timm.list_pretrained().","message":"Not all model variants have pretrained weights — timm lists models without weights too. timm.create_model('some_model', pretrained=True) raises RuntimeError if no weights exist for that variant.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your Python environment is clean or use a virtual environment. Try to install `timm` in isolation or verify dependency compatibility with other packages. Consider explicitly installing compatible versions of `timm`'s main dependencies (like `torch`, `torchvision`) before installing `timm`.","message":"Installing `timm` can lead to dependency conflicts with other packages in the environment (e.g., `torch`, `torchvision`, `Pillow`, `packaging`) or specific Python versions, resulting in `ERROR: ResolutionImpossible` during `pip install`.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T11:56:11.587Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Replace `from timm.models.layers import ...` with `from timm.layers import ...`.","cause":"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).","error":"ModuleNotFoundError: No module named 'timm.models.layers'"},{"fix":"Verify the model name against `timm.list_models(pretrained=True)`, ensure an active internet connection, and check if the model actually supports pretrained weights.","cause":"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.","error":"OSError: Specified pretrained weights did not exist for model 'model_name'. Check your entry and try again."},{"fix":"Add a batch dimension to your input tensor, typically by using `input_tensor.unsqueeze(0)` for a single image.","cause":"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.","error":"RuntimeError: Expected 4D input for conv2d, got 3D input instead"},{"fix":"Inspect 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.","cause":"The name of the final classification layer (or head) varies across different `timm` models and architectures. Common names include `head`, `fc`, or `classifier`.","error":"AttributeError: 'ResNet' object has no attribute 'fc' (or 'EfficientNet' object has no attribute 'classifier')"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":11.32,"mem_mb":142.1,"disk_size":"4.7G"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":15.07,"mem_mb":164.1,"disk_size":"4.8G"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":14.21,"mem_mb":158.8,"disk_size":"4.8G"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":13.2,"mem_mb":160.4,"disk_size":"4.8G"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":-1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":-1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":-1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":-1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":-1}]}}