# huggingface/pytorch-image-models architecture

> Architecture diagram of the GitHub repository huggingface/pytorch-image-models, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huggingface/pytorch-image-models
- Repository: https://github.com/huggingface/pytorch-image-models

## Overview

PyTorch Image Models (timm) is a vision-model library and companion toolkit for image classification and related tasks. Its principal workflow is to select a model, load or prepare image data, train or evaluate with a task-specific loss and optimization components, and use the resulting model for inference. The README also highlights multi-label classification, distillation, pretrained Hub weights, and export/validation utilities. The graph reflects documented capabilities and the sampled inference/model/data code; training-script internals were not sampled, so uncertain runtime wiring is omitted.

Main entry points: [`train.py`](https://github.com/huggingface/pytorch-image-models/blob/main/train.py) (Train CLI), [`timm/models/_factory.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_factory.py) (Model factory), [`timm/data/readers/reader_factory.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/readers/reader_factory.py) (Dataset readers), [`validate.py`](https://github.com/huggingface/pytorch-image-models/blob/main/validate.py) (Validate CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_models["Models"]
  node_factory["Model factory<br/>[_factory.py]"]
  node_registry["Model registry<br/>[_registry.py]"]
  node_architectures["Vision architectures"]
  node_layers["Neural network layers"]
  node_pretrained["Pretrained weights<br/>[_pretrained.py]"]
end

subgraph group_data["Data pipeline"]
  node_readers["Dataset readers<br/>[reader_factory.py]"]
  node_loader["Data loaders<br/>[loader.py]"]
  node_transforms["Transforms and augmentation"]
  node_mixup["Mixup and CutMix<br/>[mixup.py]"]
end

subgraph group_learning["Training and evaluation"]
  node_train["Train CLI<br/>[train.py]"]
  node_validate["Validate CLI<br/>[validate.py]"]
  node_tasks["Classification tasks<br/>[classification.py]"]
  node_distillation["Distillation tasks<br/>[distillation.py]"]
  node_losses["Loss functions<br/>[_loss_factory.py]"]
  node_optimizers["Optimizers<br/>[_optim_factory.py]"]
  node_schedulers["Learning rate schedules"]
  node_evaluator["Evaluation and metrics<br/>[evaluator.py]"]
end

subgraph group_runtime["Model use"]
  node_inference["Inference CLI<br/>[inference.py]"]
  node_checkpoint["Checkpoint utilities"]
  node_export["ONNX export<br/>[onnx_export.py]"]
  node_onnxvalidate["ONNX validation<br/>[onnx_validate.py]"]
end

node_user(("Engineer or user"))
node_dataset[("Image datasets")]
node_hub(("Hugging Face Hub"))

node_user -->|"starts training"| node_train
node_user -->|"starts evaluation"| node_validate
node_user -->|"runs inference"| node_inference
node_user -->|"requests export"| node_export
node_user -->|"provides images"| node_dataset
node_train -->|"creates model"| node_factory
node_validate -->|"creates model"| node_factory
node_inference -->|"creates model"| node_factory
node_factory -->|"looks up model"| node_registry
node_factory -->|"loads weights"| node_pretrained
node_registry -->|"resolves architecture"| node_architectures
node_architectures -->|"uses layers"| node_layers
node_pretrained -.->|"fetches weights"| node_hub
node_train -->|"builds input data"| node_readers
node_validate -->|"builds input data"| node_readers
node_inference -->|"builds input data"| node_readers
node_readers -->|"reads samples"| node_dataset
node_readers -->|"supplies samples"| node_loader
node_loader -->|"applies preprocessing"| node_transforms
node_transforms -->|"supports augmentation"| node_mixup
node_train -->|"runs task"| node_tasks
node_tasks -->|"computes objective"| node_losses
node_train -->|"updates parameters"| node_optimizers
node_train -->|"schedules learning rate"| node_schedulers
node_train -.->|"supports distillation"| node_distillation
node_validate -->|"computes metrics"| node_evaluator
node_inference -->|"loads checkpoint"| node_checkpoint
node_train -->|"saves checkpoint"| node_checkpoint
node_export -->|"creates model"| node_factory
node_onnxvalidate -->|"validates exported model"| node_export
node_user -->|"checks export"| node_onnxvalidate

click node_train "https://github.com/huggingface/pytorch-image-models/blob/main/train.py"
click node_validate "https://github.com/huggingface/pytorch-image-models/blob/main/validate.py"
click node_inference "https://github.com/huggingface/pytorch-image-models/blob/main/inference.py"
click node_factory "https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_factory.py"
click node_registry "https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_registry.py"
click node_architectures "https://github.com/huggingface/pytorch-image-models/tree/main/timm/models"
click node_layers "https://github.com/huggingface/pytorch-image-models/tree/main/timm/layers"
click node_pretrained "https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_pretrained.py"
click node_readers "https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/readers/reader_factory.py"
click node_loader "https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/loader.py"
click node_transforms "https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/transforms_factory.py"
click node_mixup "https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/mixup.py"
click node_tasks "https://github.com/huggingface/pytorch-image-models/blob/main/timm/task/classification.py"
click node_distillation "https://github.com/huggingface/pytorch-image-models/blob/main/timm/task/distillation.py"
click node_losses "https://github.com/huggingface/pytorch-image-models/blob/main/timm/loss/_loss_factory.py"
click node_optimizers "https://github.com/huggingface/pytorch-image-models/blob/main/timm/optim/_optim_factory.py"
click node_schedulers "https://github.com/huggingface/pytorch-image-models/blob/main/timm/scheduler/scheduler_factory.py"
click node_evaluator "https://github.com/huggingface/pytorch-image-models/blob/main/timm/task/evaluator.py"
click node_checkpoint "https://github.com/huggingface/pytorch-image-models/blob/main/timm/utils/checkpoint_saver.py"
click node_export "https://github.com/huggingface/pytorch-image-models/blob/main/onnx_export.py"
click node_onnxvalidate "https://github.com/huggingface/pytorch-image-models/blob/main/onnx_validate.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_factory,node_registry,node_architectures,node_layers,node_pretrained,node_user toneBlue
class node_readers,node_loader,node_transforms,node_mixup,node_dataset toneAmber
class node_train,node_validate,node_tasks,node_distillation,node_losses,node_optimizers,node_schedulers,node_evaluator toneMint
class node_inference,node_checkpoint,node_export,node_onnxvalidate toneRose
class node_hub toneIndigo
```

## Components

### Models

- [Model factory](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_factory.py): `timm/models/_factory.py`
- [Model registry](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_registry.py): `timm/models/_registry.py`
- [Vision architectures](https://github.com/huggingface/pytorch-image-models/tree/main/timm/models): `timm/models`
- [Neural network layers](https://github.com/huggingface/pytorch-image-models/tree/main/timm/layers): `timm/layers`
- [Pretrained weights](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/_pretrained.py): `timm/models/_pretrained.py`

### Data pipeline

- [Dataset readers](https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/readers/reader_factory.py): `timm/data/readers/reader_factory.py`
- [Data loaders](https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/loader.py): `timm/data/loader.py`
- [Transforms and augmentation](https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/transforms_factory.py): `timm/data/transforms_factory.py`
- [Mixup and CutMix](https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/mixup.py): `timm/data/mixup.py`

### Training and evaluation

- [Train CLI](https://github.com/huggingface/pytorch-image-models/blob/main/train.py): `train.py`
- [Validate CLI](https://github.com/huggingface/pytorch-image-models/blob/main/validate.py): `validate.py`
- [Classification tasks](https://github.com/huggingface/pytorch-image-models/blob/main/timm/task/classification.py): `timm/task/classification.py`
- [Distillation tasks](https://github.com/huggingface/pytorch-image-models/blob/main/timm/task/distillation.py): `timm/task/distillation.py`
- [Loss functions](https://github.com/huggingface/pytorch-image-models/blob/main/timm/loss/_loss_factory.py): `timm/loss/_loss_factory.py`
- [Optimizers](https://github.com/huggingface/pytorch-image-models/blob/main/timm/optim/_optim_factory.py): `timm/optim/_optim_factory.py`
- [Learning rate schedules](https://github.com/huggingface/pytorch-image-models/blob/main/timm/scheduler/scheduler_factory.py): `timm/scheduler/scheduler_factory.py`
- [Evaluation and metrics](https://github.com/huggingface/pytorch-image-models/blob/main/timm/task/evaluator.py): `timm/task/evaluator.py`

### Model use

- [Inference CLI](https://github.com/huggingface/pytorch-image-models/blob/main/inference.py): `inference.py`
- [Checkpoint utilities](https://github.com/huggingface/pytorch-image-models/blob/main/timm/utils/checkpoint_saver.py): `timm/utils/checkpoint_saver.py`
- [ONNX export](https://github.com/huggingface/pytorch-image-models/blob/main/onnx_export.py): `onnx_export.py`
- [ONNX validation](https://github.com/huggingface/pytorch-image-models/blob/main/onnx_validate.py): `onnx_validate.py`

### Other components

- **Engineer or user**
- **Image datasets**
- **Hugging Face Hub**

## Connections

- Engineer or user → Train CLI: starts training
- Engineer or user → Validate CLI: starts evaluation
- Engineer or user → Inference CLI: runs inference
- Engineer or user → ONNX export: requests export
- Engineer or user → Image datasets: provides images
- Train CLI → Model factory: creates model
- Validate CLI → Model factory: creates model
- Inference CLI → Model factory: creates model
- Model factory → Model registry: looks up model
- Model factory → Pretrained weights: loads weights
- Model registry → Vision architectures: resolves architecture
- Vision architectures → Neural network layers: uses layers
- Pretrained weights → Hugging Face Hub: fetches weights
- Train CLI → Dataset readers: builds input data
- Validate CLI → Dataset readers: builds input data
- Inference CLI → Dataset readers: builds input data
- Dataset readers → Image datasets: reads samples
- Dataset readers → Data loaders: supplies samples
- Data loaders → Transforms and augmentation: applies preprocessing
- Transforms and augmentation → Mixup and CutMix: supports augmentation
- Train CLI → Classification tasks: runs task
- Classification tasks → Loss functions: computes objective
- Train CLI → Optimizers: updates parameters
- Train CLI → Learning rate schedules: schedules learning rate
- Train CLI → Distillation tasks: supports distillation
- Validate CLI → Evaluation and metrics: computes metrics
- Inference CLI → Checkpoint utilities: loads checkpoint
- Train CLI → Checkpoint utilities: saves checkpoint
- ONNX export → Model factory: creates model
- ONNX validation → ONNX export: validates exported model
- Engineer or user → ONNX validation: checks export
