# lengstrom/fast-style-transfer architecture

> Architecture diagram of the GitHub repository lengstrom/fast-style-transfer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lengstrom/fast-style-transfer
- Repository: https://github.com/lengstrom/fast-style-transfer

## Overview

This repository trains fast artistic style-transfer networks and applies saved checkpoints to images or video. The main workflow is to train a transformation network from a style image and content-image collection, then use the checkpoint to stylize image files or video frames. VGG19 supplies perceptual features during training; image utilities handle loading and saving. The video entry point delegates frame processing to evaluation code. Relationships reflect the excerpts and README; unsampled details are not inferred.

Main entry points: [`evaluate.py`](https://github.com/lengstrom/fast-style-transfer/blob/master/evaluate.py) (Image and frame evaluation), [`src/optimize.py`](https://github.com/lengstrom/fast-style-transfer/blob/master/src/optimize.py) (Loss optimization), [`style.py`](https://github.com/lengstrom/fast-style-transfer/blob/master/style.py) (Training command), [`src/utils.py`](https://github.com/lengstrom/fast-style-transfer/blob/master/src/utils.py) (Image utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Network training"]
  node_style_cli["Training command<br/>[style.py]"]
  node_optimizer["Loss optimization<br/>[optimize.py]"]
  node_checkpoint["Model checkpoint"]
end

subgraph group_inference["Stylization"]
  node_evaluate["Image and frame evaluation<br/>[evaluate.py]"]
  node_video_cli["Video command<br/>[transform_video.py]"]
end

subgraph group_internals["Model internals"]
  node_image_io["Image utilities<br/>[utils.py]"]
  node_vgg["VGG19 features<br/>[vgg.py]"]
  node_transform_net["Transform network<br/>[transform.py]"]
end

node_user(("User"))
node_content_images["Content images"]
node_style_image["Style image"]
node_stylized_output["Stylized output"]

node_user -->|"trains via"| node_style_cli
node_style_cli -->|"calls"| node_optimizer
node_style_cli -->|"loads inputs"| node_image_io
node_optimizer -->|"loads content"| node_image_io
node_optimizer -->|"extracts features"| node_vgg
node_optimizer -->|"builds network"| node_transform_net
node_optimizer -->|"saves"| node_checkpoint
node_content_images -->|"provides content"| node_style_cli
node_style_image -->|"provides style"| node_style_cli
node_user -->|"runs inference"| node_evaluate
node_evaluate -->|"builds predictions"| node_transform_net
node_evaluate -->|"loads and saves"| node_image_io
node_checkpoint -->|"restores"| node_evaluate
node_evaluate -->|"writes"| node_stylized_output
node_user -->|"runs video styling"| node_video_cli
node_video_cli -->|"delegates frames"| node_evaluate
node_evaluate -->|"writes video frames"| node_stylized_output

click node_style_cli "https://github.com/lengstrom/fast-style-transfer/blob/master/style.py"
click node_optimizer "https://github.com/lengstrom/fast-style-transfer/blob/master/src/optimize.py"
click node_image_io "https://github.com/lengstrom/fast-style-transfer/blob/master/src/utils.py"
click node_vgg "https://github.com/lengstrom/fast-style-transfer/blob/master/src/vgg.py"
click node_transform_net "https://github.com/lengstrom/fast-style-transfer/blob/master/src/transform.py"
click node_evaluate "https://github.com/lengstrom/fast-style-transfer/blob/master/evaluate.py"
click node_video_cli "https://github.com/lengstrom/fast-style-transfer/blob/master/transform_video.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_style_cli,node_optimizer,node_checkpoint,node_user toneBlue
class node_evaluate,node_video_cli toneAmber
class node_image_io,node_vgg,node_transform_net toneMint
class node_content_images,node_style_image,node_stylized_output toneIndigo
```

## Components

### Network training

- [Training command](https://github.com/lengstrom/fast-style-transfer/blob/master/style.py): `style.py`
- [Loss optimization](https://github.com/lengstrom/fast-style-transfer/blob/master/src/optimize.py): `src/optimize.py`
- **Model checkpoint**

### Stylization

- [Image and frame evaluation](https://github.com/lengstrom/fast-style-transfer/blob/master/evaluate.py): `evaluate.py`
- [Video command](https://github.com/lengstrom/fast-style-transfer/blob/master/transform_video.py): `transform_video.py`

### Model internals

- [Image utilities](https://github.com/lengstrom/fast-style-transfer/blob/master/src/utils.py): `src/utils.py`
- [VGG19 features](https://github.com/lengstrom/fast-style-transfer/blob/master/src/vgg.py): `src/vgg.py`
- [Transform network](https://github.com/lengstrom/fast-style-transfer/blob/master/src/transform.py): `src/transform.py`

### Other components

- **User**
- **Content images**
- **Style image**
- **Stylized output**

## Connections

- User → Training command: trains via (evidence: `README.md`)
- Training command → Loss optimization: calls (evidence: `style.py`)
- Training command → Image utilities: loads inputs (evidence: `style.py`)
- Loss optimization → Image utilities: loads content (evidence: `src/optimize.py`)
- Loss optimization → VGG19 features: extracts features (evidence: `src/optimize.py`)
- Loss optimization → Transform network: builds network (evidence: `src/optimize.py`)
- Loss optimization → Model checkpoint: saves (evidence: `src/optimize.py`)
- Content images → Training command: provides content (evidence: `README.md`)
- Style image → Training command: provides style (evidence: `README.md`)
- User → Image and frame evaluation: runs inference (evidence: `README.md`)
- Image and frame evaluation → Transform network: builds predictions (evidence: `evaluate.py`)
- Image and frame evaluation → Image utilities: loads and saves (evidence: `evaluate.py`)
- Model checkpoint → Image and frame evaluation: restores (evidence: `evaluate.py`)
- Image and frame evaluation → Stylized output: writes (evidence: `evaluate.py`)
- User → Video command: runs video styling (evidence: `README.md`)
- Video command → Image and frame evaluation: delegates frames (evidence: `transform_video.py`)
- Image and frame evaluation → Stylized output: writes video frames (evidence: `evaluate.py`)
