# shradha-khapra/ai-nst-project architecture

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

- Interactive diagram: https://gitdiagram.com/shradha-khapra/ai-nst-project
- Repository: https://github.com/shradha-khapra/ai-nst-project

## Overview

This repository implements AdaIN neural style transfer with a Flask upload-and-render interface and a separate model-training workflow. Inference accepts content and style images plus an alpha blend, encodes both, normalizes content features using style statistics, decodes and saves the result for display. Training builds paired image batches, optimizes the decoder against content and style losses, and saves checkpoints. Source excerpts establish the web and training calls; README has no further capability detail, so assets and unsampled routes are not expanded.

Main entry points: [`NST_Code/train.py`](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/train.py) (Training loop), [`NST_Code/app.py`](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py) (Flask routes), [`NST_Code/utils/models.py`](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/models.py) (VGG encoder), [`NST_Code/utils/utils.py`](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py) (Image dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web inference"]
  node_webapp["Flask routes<br/>[app.py]"]
  node_upload["Image uploads<br/>[app.py]"]
  node_render["Result page<br/>[index.html]"]
end

subgraph group_transfer["Style transfer"]
  node_transfer_fn["Inference transfer<br/>[app.py]"]
  node_encoder["VGG encoder<br/>[models.py]"]
  node_decoder["Decoder<br/>[models.py]"]
  node_adain["AdaIN statistics<br/>[utils.py]"]
  node_save["Image encoding<br/>[app.py]"]
end

subgraph group_training["Model training"]
  node_trainer["Training loop<br/>[train.py]"]
  node_dataset["Image dataset<br/>[utils.py]"]
  node_transforms["Training transforms<br/>[utils.py]"]
  node_loss["Training losses<br/>[train.py]"]
end

subgraph group_storage["Image and model data"]
  node_images[("Image collections")]
  node_styles[("Style collections")]
  node_uploads[("Uploaded and output images")]
  node_weights[("Model weights<br/>[decoder_final.pth]")]
  node_vgg_weights[("VGG weights<br/>[vgg_normalised.pth]")]
end

node_visitor(("User"))

node_visitor -->|"submits images"| node_webapp
node_webapp -->|"saves uploads"| node_upload
node_webapp -->|"runs transfer"| node_transfer_fn
node_transfer_fn -->|"encodes images"| node_encoder
node_transfer_fn -->|"normalizes features"| node_adain
node_transfer_fn -->|"decodes features"| node_decoder
node_webapp -->|"saves result"| node_save
node_webapp -->|"reads and writes"| node_uploads
node_webapp -->|"renders page"| node_render
node_webapp -->|"serves result"| node_visitor
node_trainer -->|"constructs datasets"| node_dataset
node_trainer -->|"gets transforms"| node_transforms
node_trainer -->|"encodes batches"| node_encoder
node_trainer -->|"trains decoder"| node_decoder
node_trainer -->|"normalizes features"| node_adain
node_trainer -->|"computes losses"| node_loss
node_dataset -->|"loads images"| node_images
node_trainer -->|"loads checkpoint"| node_weights
node_encoder -->|"loads weights"| node_vgg_weights

click node_webapp "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py"
click node_upload "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py"
click node_render "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/templates/index.html"
click node_transfer_fn "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py"
click node_encoder "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/models.py"
click node_decoder "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/models.py"
click node_adain "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py"
click node_save "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py"
click node_trainer "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/train.py"
click node_dataset "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py"
click node_transforms "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py"
click node_loss "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/train.py"
click node_images "https://github.com/shradha-khapra/ai-nst-project/tree/main/NST_Code/content_data"
click node_styles "https://github.com/shradha-khapra/ai-nst-project/tree/main/NST_Code/style_data"
click node_uploads "https://github.com/shradha-khapra/ai-nst-project/tree/main/NST_Code/static/uploads"
click node_weights "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/experiment/final_exp/decoder_final.pth"
click node_vgg_weights "https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/vgg_normalised.pth"

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_webapp,node_upload,node_render,node_visitor toneBlue
class node_transfer_fn,node_encoder,node_decoder,node_adain,node_save toneAmber
class node_trainer,node_dataset,node_transforms,node_loss toneMint
class node_images,node_styles,node_uploads,node_weights,node_vgg_weights toneRose
```

## Components

### Web inference

- [Flask routes](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py): `NST_Code/app.py`
- [Image uploads](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py): `NST_Code/app.py`
- [Result page](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/templates/index.html): `NST_Code/templates/index.html`

### Style transfer

- [Inference transfer](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py): `NST_Code/app.py`
- [VGG encoder](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/models.py): `NST_Code/utils/models.py`
- [Decoder](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/models.py): `NST_Code/utils/models.py`
- [AdaIN statistics](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py): `NST_Code/utils/utils.py`
- [Image encoding](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/app.py): `NST_Code/app.py`

### Model training

- [Training loop](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/train.py): `NST_Code/train.py`
- [Image dataset](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py): `NST_Code/utils/utils.py`
- [Training transforms](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/utils/utils.py): `NST_Code/utils/utils.py`
- [Training losses](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/train.py): `NST_Code/train.py`

### Image and model data

- [Image collections](https://github.com/shradha-khapra/ai-nst-project/tree/main/NST_Code/content_data): `NST_Code/content_data`
- [Style collections](https://github.com/shradha-khapra/ai-nst-project/tree/main/NST_Code/style_data): `NST_Code/style_data`
- [Uploaded and output images](https://github.com/shradha-khapra/ai-nst-project/tree/main/NST_Code/static/uploads): `NST_Code/static/uploads`
- [Model weights](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/experiment/final_exp/decoder_final.pth): `NST_Code/experiment/final_exp/decoder_final.pth`
- [VGG weights](https://github.com/shradha-khapra/ai-nst-project/blob/main/NST_Code/vgg_normalised.pth): `NST_Code/vgg_normalised.pth`

### Other components

- **User**

## Connections

- User → Flask routes: submits images (evidence: `NST_Code/app.py`)
- Flask routes → Image uploads: saves uploads (evidence: `NST_Code/app.py`)
- Flask routes → Inference transfer: runs transfer (evidence: `NST_Code/app.py`)
- Inference transfer → VGG encoder: encodes images (evidence: `NST_Code/app.py`)
- Inference transfer → AdaIN statistics: normalizes features (evidence: `NST_Code/app.py`)
- Inference transfer → Decoder: decodes features (evidence: `NST_Code/app.py`)
- Flask routes → Image encoding: saves result (evidence: `NST_Code/app.py`)
- Flask routes → Uploaded and output images: reads and writes (evidence: `NST_Code/app.py`)
- Flask routes → Result page: renders page (evidence: `NST_Code/app.py`)
- Flask routes → User: serves result (evidence: `NST_Code/app.py`)
- Training loop → Image dataset: constructs datasets (evidence: `NST_Code/train.py`)
- Training loop → Training transforms: gets transforms (evidence: `NST_Code/train.py`)
- Training loop → VGG encoder: encodes batches (evidence: `NST_Code/train.py`)
- Training loop → Decoder: trains decoder (evidence: `NST_Code/train.py`)
- Training loop → AdaIN statistics: normalizes features (evidence: `NST_Code/train.py`)
- Training loop → Training losses: computes losses (evidence: `NST_Code/train.py`)
- Image dataset → Image collections: loads images (evidence: `NST_Code/utils/utils.py`)
- Training loop → Model weights: loads checkpoint
- VGG encoder → VGG weights: loads weights (evidence: `NST_Code/utils/models.py`)
