The largest collection of PyTorch image encoders / backbones. Including train, eval, inference, export scripts, and pretrained weights -- ResNet, ResNeXT, EfficientNet, NFNet, Vision Transformer (ViT)
翻譯準備中
開發工具Python · MDXGitHub @huggingface自行安裝營運者未確認
試用過了嗎? 點一下就好,不需要登入。
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
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗forward_intermediates() and prune_intermediate_layers() are now supported by every model. Newly added for CSPNet, NFNet, DLA, DenseNet (#2870, thanks ghaith-mq), CoaT, ConViT, ConvMixer, CrossViT, HRNet, Inception-v3, Inception-ResNet-v2, NASNet, PNASNet, SelecSLS, SENet, Sequencer2d, VGG, Visformer, Xception and Aligned Xception, with prune_intermediate_layers() for NaFlexViT and MobileNetV5 encoders. CoaT, ConViT, ConvMixer, CrossViT and Visformer gain features_only support.prune_intermediate_layers() fixes
prune_head=True removes the whole head (head norm, pre-logits layers, attention pooling) so the pruned model leaves no unused params (DDP w/o find_unused_parameters), except CoaT, CrossViT and HRNet when only some of their parallel scales / branches are taken. Pass prune_head=False to keep it.forward_features() ends at the last kept feature and num_features / head_hidden_size match it. Pruning to the stem feature removes the stem pooling after it.stop_early, class token / post network removal, and TorchScript of pruned / feature_cls='getter' models across many families.head_hidden_size is the actual pre-logits (pooled) width in all models, including concat pooling (catavgmax) and after reset_classifier(). Pool types a model can't apply now raise at creation / reset instead of being silently ignored or failing in forward.num_classes=0 output is the class token embedding (matching forward_head(pre_logits=True)), vit_pe_core reset_classifier() w/ a non map pool removes the attention pool, pool type export via save_for_hf reads the head's current pooling, and headless (num_classes=0) Swin, SwinV2, DaViT and NextViT checkpoints reload correctly.sweep.py: grid / random search over any train.py argument, one effective --config per job, run on a pool of local GPUs and resumable. WSD sweeps train one stable trunk per hyperparameter combination and branch independent cooldowns from its milestone checkpoints, comparing annealing at several budgets for a fraction of the cost of full runs. See the training docs.train.py: --resume auto resumes in place from the experiment's own last.pth.tar (checkpoint history, model_best and summary.csv stay consistent), --stop-epoch N stops without changing the schedule, --save-epochs N [N ...] keeps milestone-N.pth.tar snapshots, and YAML --config values are validated against the script's arguments.PlateauLRScheduler (--sched plateau). timm schedulers are stateless functions of the epoch or update count, the metric-driven plateau schedule never fit that and its state is not checkpointed, so resume was never exact. Use cosine or wsd.reset_classifier() keeps the current pooling in all models, unknown constructor args raise TypeError everywhere, Swin family dynamic_img_size, LeViT layer-wise lr decay, no_weight_decay names that matched no params (NesT, SwinV2, XCiT, FocalNet), resize state recorded for all set_input_size families.save_for_hf stale test input size, EfficientViT (MSRA) rectangular resize, ImageDataset image conversion errors (#2846). reparameterize_model moved to timm.models.cspnext_{tiny,s,m,l,x} with ImageNet-1k classification weights converted from OpenMMLab. Thanks Munehiro Kobayashi.TIMM_FOREACH_CHUNK_SIZE to override).clipping_threshold) for AdamWLegacy / NAdamW, new decoupled / corrected weight decay NovoGrad variants (novogradw, novogradc).p.grad
modification.torch.compile / CUDA graph fixes for Adopt, SGDW, AdafactorBV.--sched wsd, --lr-decay-fn, --lr-stable-timescale).set_input_size()
window_size / window_ratio supported. Fixes Swin S3 and SwinV2 window16 / window12 models
changing outputs on a same-size call.train.py w/ --sched none, and eval center crop
interpolation for non-square inputs.--task multilabel to train.py / validate.py, trained with BCE (MultiLabelClassificationTask). See the
training docs for details.--target-format multihot), or one binary field
per class (--target-key a,b,c), with / paths into nested fields. Supported by the hfds, hfids, tfds
(multi-field keys), and wds readers.--eval-metric) plus micro, macro, and sample F1, with an F1 threshold set by
--multilabel-threshold.--loss
class_weights.py.batchmean reductiongrid_type and normalize_coords options to the Fourier / rotary builders (build_fourier_pos_embed,
build_rotary_pos_embed) and axial RoPE modules, and configurable MRoPE sections in EVA.rotate_half in the tuple-output RotaryEmbedding and the base factory variant.inference.py input-size selection, and improve --model-kwargs parsing.torch.compile and tensor learning-rate support.forward_intermediates (NaFlex dict input) support.weights_only=True, add safe_global for ArgParse.is_causal through for SSL tasks.ParallelScalingBlock (& DiffParallelScalingBlock)
timm models but could impact downstream use.dpwee, dwee, dlittle (differential) ViTs with a small boost over previous runs
timm variant of the CSATv2 model at 512x512 & 640x640
__init__ into a common method that can be externally called via init_non_persistent_buffers() after meta-device init.timm Muon impl. Appears more competitive vs AdamW with familiar hparams for image tasks.DiffAttention), add corresponding DiffParallelScalingBlock (for ViT), train some wee vits
LsePlus and SimPoolDropBlock2d (also add support to ByobNet based models)nesterov=True) updates if muon not suitable for parameter shape (or excluded via param group flag)adjust_lr_fnns_coefficientstimmlvd_1689m -> lvd1689m to match (same for sat_493m -> sat493m)PyTorch Image Models (timm) is a collection of image models, layers, utilities, optimizers, schedulers, data-loaders / augmentations, and reference training / validation scripts that aim to pull together a wide variety of SOTA models with ability to reproduce ImageNet training results.
The work of many others is present here. I've tried to make sure all source material is acknowledged via links to github, arxiv papers, etc in the README, documentation, and code docstrings. Please let me know if I missed anything.
All model architecture families include variants with pretrained weights. There are specific model variants without any weights, it is NOT a bug. Help training new or better weights is always appreciated.
To see full list of optimizers w/ descriptions: timm.optim.list_optimizers(with_description=True)
Included optimizers available via timm.optim.create_optimizer_v2 factory method:
adabelief an implementation of AdaBelief adapted from https://github.com/juntang-zhuang/Adabelief-Optimizer - https://arxiv.org/abs/2010.07468adafactor adapted from FAIRSeq impl - https://arxiv.org/abs/1804.04235adafactorbv adapted from Big Vision - https://arxiv.org/abs/2106.04560adahessian by David Samuel - https://arxiv.org/abs/2006.00719adamp and sgdp by Naver ClovAI - https://arxiv.org/abs/2006.08217adamuon and nadamuon as per https://github.com/Chongjie-Si/AdaMuon - https://arxiv.org/abs/2507.11005adan an implementation of Adan adapted from https://github.com/sail-sg/Adan - https://arxiv.org/abs/2208.06677adopt ADOPT adapted from https://github.com/iShohei220/adopt - Several (less common) features that I often utilize in my projects are included. Many of their additions are the reason why I maintain my own set of models, instead of using others' via PIP:
get_classifier and reset_classifierforward_features (see documentation)create_model(name, features_only=True, out_indices=..., output_stride=...)out_indices creation arg specifies which feature maps to return, these indices are 0 based and generally correspond to the C(i + 1) feature level.output_stride creation arg controls output stride of the network by using dilated convolutions. Most networks are stride 32 by default. Not all networks support this..feature_info memberModel validation results can be found in the results tables
The official documentation can be found at https://huggingface.co/docs/hub/timm. Documentation contributions are welcome.
Getting Started with PyTorch Image Models (timm): A Practitioner’s Guide by Chris Hughes is an extensive blog post covering many aspects of timm in detail.
timmdocs is an alternate set of documentation for timm. A big thanks to Aman Arora for his efforts creating timmdocs.
paperswithcode is a good resource for browsing the models within timm.
The root folder of the repository contains reference train, validation, and inference scripts that work with the included models and other features of this repository. They are adaptable for other datasets and use cases with a little hacking. See documentation.
One of the greatest assets of PyTorch is the community and their contributions. A few of my favourite resources that pair well with the models and components here are listed below.
The code here is licensed Apache 2.0. I've taken care to make sure any third party code included or adapted has compatible (permissive) licenses such as MIT, BSD, etc. I've made an effort to avoid any GPL / LGPL conflicts. That said, it is your responsibility to ensure you comply with licenses here and conditions of any dependent licenses. Where applicable, I've linked the sources/references for various components in docstrings. If you think I've missed anything please create an issue.
So far all of the pretrained weights available here are pretrained on ImageNet with a select few that have some additional pretraining (see extra note below). ImageNet was released for non-commercial research purposes only (https://image-net.org/download). It's not clear what the implications of that are for the use of pretrained weights from that dataset. Any models I have trained with ImageNet are done for research purposes and one should assume that the original dataset license applies to the weights. It's best to seek legal advice if you intend to use the pretrained weights in a commercial product.
Several weights included or references here were pretrained with proprietary datasets that I do not have access to. These include the Facebook WSL, SSL, SWSL ResNe(Xt) and the Google Noisy Student EfficientNet models. The Facebook models have an explicit non-commercial license (CC-BY-NC 4.0, https://github.com/facebookresearch/semi-supervised-ImageNet1K-models, https://github.com/facebookresearch/WSL-Images). The Google models do not appear to have any restriction beyond the Apache 2.0 license (and ImageNet concerns). In either case, you should contact Facebook or Google with any questions.
@misc{rw2019timm,
author = {Ross Wightman},
title = {PyTorch Image Models},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
doi = {10.5281/zenodo.4414861},
howpublished = {\url{https://github.com/rwightman/pytorch-image-models}}
}
grid_indexing='xy' now swaps
coordinate channels as requested; outputs for these previously incorrect configurations change.apply_rot_embed, apply_rot_embed_cat, and apply_rot_embed_list return each input's dtype, casting after
the rotation without first downcasting sin/cos.bands
buffer is now retained in both cached and dynamic modes (rope.bands is no longer None in cached mode).kron PSGD w/ Kronecker-factored preconditioner from https://github.com/evanatyourservice/kron_torch - https://sites.google.com/site/lixilinx/home/psgdlamb an implementation of Lamb and LambC (w/ trust-clipping) cleaned up and modified to support use with XLA - https://arxiv.org/abs/1904.00962laprop optimizer from https://github.com/Z-T-WANG/LaProp-Optimizer - https://arxiv.org/abs/2002.04839lars an implementation of LARS and LARC (w/ trust-clipping) - https://arxiv.org/abs/1708.03888lion and implementation of Lion adapted from https://github.com/google/automl/tree/master/lion - https://arxiv.org/abs/2302.06675lookahead adapted from impl by Liam - https://arxiv.org/abs/1907.08610madgrad an implementation of MADGRAD adapted from https://github.com/facebookresearch/madgrad - https://arxiv.org/abs/2101.11075mars MARS optimizer from https://github.com/AGI-Arena/MARS - https://arxiv.org/abs/2411.10438muon MUON optimizer from https://github.com/KellerJordan/Muon with numerous additions and improved non-transformer behaviournadam an implementation of Adam w/ Nesterov momentumnadamw an implementation of AdamW (Adam w/ decoupled weight-decay) w/ Nesterov momentum. A simplified impl based on https://github.com/mlcommons/algorithmic-efficiencynovograd by Masashi Kimura - https://arxiv.org/abs/1905.11286radam by Liyuan Liu - https://arxiv.org/abs/1908.03265rmsprop_tf adapted from PyTorch RMSProp by myself. Reproduces much improved Tensorflow RMSProp behavioursgdw and implementation of SGD w/ decoupled weight-decayfused<name> optimizers by name with NVIDIA Apex installedbnb<name> optimizers by name with BitsAndBytes installedcadamw, clion, and more 'Cautious' optimizers from https://github.com/kyleliang919/C-Optim - https://arxiv.org/abs/2411.16085adam, adamw, rmsprop, adadelta, adagrad, and sgd pass through to torch.optim implementationsc suffix (eg adamc, nadamc to implement 'corrected weight decay' in https://arxiv.org/abs/2506.02285)step, cosine w/ restarts, tanh w/ restarts, plateau