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
What is PyTorch Image Models (timm)?
timm is a library of ready‑to‑use computer‑vision models built on top of PyTorch. It bundles:
- Hundreds of state‑of‑the‑art image architectures – from classic ConvNets (ResNet, EfficientNet, MobileNet) to modern Vision Transformers (ViT, EVA, BEiT, ConvNeXt, etc.).
- Pre‑trained weights for most of those models, usually trained on ImageNet‑1k, so you can start using them for inference or fine‑tuning right away.
- Utility code – layers, optimizers, learning‑rate schedulers, data loaders, augmentation pipelines, and reference training/validation scripts that let you reproduce published results with minimal setup.
- Training helpers – a new
sweep.pyfor hyper‑parameter sweeps, a flexibletrain.pythat supports resuming, multi‑GPU runs, multi‑label classification, custom loss functions, and more.
In short, timm is a one‑stop shop for researchers and engineers who need a wide variety of image models without having to re‑implement each architecture from scratch.
Who might find it useful?
| Audience | Why it matters |
|---|---|
| ML researchers | Quickly prototype new ideas on top of a large catalog of SOTA vision models and compare results. |
| Practitioners / engineers | Pull a pre‑trained model into a production pipeline with a single import, then fine‑tune on a custom dataset. |
| Students / hobbyists | Learn about modern vision architectures by reading clean, well‑documented PyTorch code. |
| Benchmarking teams | Use the provided training scripts and benchmark CSVs to measure speed/accuracy on different GPUs. |
Core features (as described in the README)
| Feature | Details |
|---|---|
| Model zoo | > 300 architectures, each with variant‑specific pretrained weights. Includes ConvNets, Transformers, hybrid models, and niche backbones like CPUBone for low‑power devices. |
| Training scripts | train.py and validate.py support resume, epoch stopping, milestone checkpoints, YAML config validation, multi‑label tasks, custom loss functions, and mixed‑precision. |
| Hyper‑parameter sweeps | New sweep.py runs grid or random searches over any train.py argument, distributes jobs across local GPUs, and can resume interrupted sweeps. |
| Optimizers & schedulers | Updated implementations for RMSpropTF, LaProp, LAMB, LARS, AdaBelief, NovoGrad, Muon, etc., plus a warmup‑stable‑decay (WSD) LR scheduler. |
| Data utilities | Flexible image datasets, multi‑label support, Mixup/CutMix, AugMix, and automatic handling of non‑square or single‑channel images. |
| Model resizing | set_input_size() lets most models adapt to different image resolutions on the fly, with special handling for windowed Vision Transformers. |
| Export & inference | ONNX export compatibility, inference.py with automatic input‑size selection, and support for Torch‑compile and CUDA graphs. |
| Documentation | Model API pages, training guides, and a curated list of awesome PyTorch resources. |
| Licensing & citation | Clear license information for each model and instructions on how to cite the library. |
How to get started (quick‑start steps)
- Install
pip install timm - Load a model (e.g., a pretrained EfficientNet‑B0)
import timm model = timm.create_model('efficientnet_b0', pretrained=True) model.eval() - Run inference
from torchvision import transforms from PIL import Image preprocess = transforms.Compose([ transforms.Resize(256), transforms.CenterCrop(224), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) img = Image.open('my_image.jpg') input_tensor = preprocess(img).unsqueeze(0) # batch dim with torch.no_grad(): logits = model(input_tensor) - Fine‑tune – use the provided
train.pyscript, point it at your dataset, and optionally run a sweep:python train.py --model efficientnet_b0 --data-dir /path/to/data --epochs 30 python sweep.py --config my_sweep.yaml
When to consider alternatives
- If you need non‑vision models (LLMs, audio, RL agents),
timmdoes not cover those domains. - For very large‑scale training (billions of images) you may want a dedicated distributed training framework (e.g., DeepSpeed, Lightning) that integrates with
timmbut provides extra scaling features. - If you require on‑device inference (mobile/embedded), look at the lightweight backbones like CPUBone or MobileNet‑V2, but you may still need to convert the model to ONNX/TFLite separately.
TL;DR – timm is a comprehensive, actively maintained collection of image models and training utilities for PyTorch, ideal for anyone wanting to experiment with or deploy state‑of‑the‑art computer‑vision architectures.
Related
- Dispatch
- Dispatch
- Project
- Project
- Project