# cust0s/high-res-singan architecture

> Architecture diagram of the GitHub repository cust0s/high-res-singan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cust0s/high-res-singan
- Repository: https://github.com/cust0s/high-res-singan

## Overview

##### Project Type and Purpose
- This is a deep-learning image-processing pipeline based on SinGAN, extended for high-resolution (up to 500×500px) single-image generation.
- It provides two HR methods (structural re-parameterization in HR.py and patch-splicing in splicing.py), plus auxiliary scripts for random sampling, editing, harmonization, painting, and animation.

##### High-Level Architectural Components
A. Command-Line Orchestrators (green rectangles)
- main_train.py / SR.py: Standard-resolution SinGAN training
- HR.py: High-res method 1 (automatic pyramid expansion)
- splicing.py: High-res method 2 (divide-and-splice)
- editing.py, harmonization.py, paint2image.py, random_samples.py, animation.py: downstream tasks on trained models
B. Core Model Library (blue rectangles)
- SinGAN/
- functions.py: image pyramid ops, noise injection
- imresize.py: multi-scale resizing utilities
- models.py: generator/discriminator definitions
- training.py: multi-scale adversarial training loop
- manipulate.py / splicing_functions.py: sample generation & patch stitching
- SIFID/
- inception.py: feature extractor
- sifid_score.py: spectral‐distance evaluation metric
- config.py: hyperparameters and default settings
- Input/Images, Input/Splicing, Input/Paint, Input/Harmonization, Input/Editing: raw inputs per task
- samples/, samples/HR_method/, samples/splicing_method/: generated outputs
D. Metrics & Evaluation (purple rectangle)
- SIFID module invoked after generation to compute quality scores (SIFID.npy for thresholds)

##### Data Flow & Component Interactions
1. User invokes a CLI script →
2. config.py loads experiment settings →
3. Input manager locates the source image(s) →
4. For training:
- SinGAN.training builds an image pyramid →
- models.py defines GAN at each scale →
- functions.py / imresize.py handle multi-scale operations →
5. Checkpoints are saved →
6. For generation:
- manipulate.py (method1) or splicing_functions.py (method2) produces outputs →
7. SIFID module computes fidelity →
8. Results are saved to samples/… directories →
9. Downstream scripts (editing, paint2image, harmonization) consume pretrained models

##### Architectural Patterns & Principles
- Pipeline segmentation by scale and function (separation of concerns)
- Plugin-style CLI entrypoints for each task
- Modular ML components (training, sampling, evaluation)
- Reuse of core SinGAN code for all variations

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Command-Line Orchestrators
    subgraph "Command-Line Orchestrators"
        direction TB
        main_train["main_train.py"]:::cli
        SR["SR.py"]:::cli
        HR["HR.py"]:::cli
        splicing["splicing.py"]:::cli
        editing["editing.py"]:::cli
        harmonization["harmonization.py"]:::cli
        paint2image["paint2image.py"]:::cli
        random_samples["random_samples.py"]:::cli
        animation["animation.py"]:::cli
    end

    %% Configuration & Data
    subgraph "Configuration & Data"
        direction TB
        config["config.py"]:::config
        InputImages["Input/Images"]:::data
        InputEditing["Input/Editing"]:::data
        InputHarmonization["Input/Harmonization"]:::data
        InputPaint["Input/Paint"]:::data
        InputSplicing["Input/Splicing"]:::data
        samples["samples/"]:::data
        samplesHR["samples/HR_method"]:::data
        samplesSp["samples/splicing_method"]:::data
        samplesRand["samples/RandomSamples"]:::data
    end

    %% Core Model Library
    subgraph "Core Model Library"
        direction TB
        SinGAN_dir["SinGAN/"]:::library
        functions["functions.py"]:::library
        imresize["imresize.py"]:::library
        models["models.py"]:::library
        training["training.py"]:::library
        manipulate["manipulate.py"]:::library
        splicing_funcs["splicing_functions.py"]:::library
    end

    %% Evaluation Library
    subgraph "Evaluation Library"
        direction TB
        inception["inception.py"]:::eval
        sifid_score["sifid_score.py"]:::eval
        SIFID_npy["SIFID.npy"]:::data
    end

    %% Flows: Orchestrators to Config
    main_train -->|"load settings"| config
    SR -->|"load settings"| config
    HR -->|"load settings"| config
    splicing -->|"load settings"| config
    editing -->|"load settings"| config
    harmonization -->|"load settings"| config
    paint2image -->|"load settings"| config
    random_samples -->|"load settings"| config
    animation -->|"load settings"| config

    %% Config to Inputs
    config -->|"select source image"| InputImages

    %% Training pipelines
    main_train -->|"start training"| training
    SR -->|"start training"| training
    HR -->|"method1 pipeline"| training
    splicing -->|"method2 pipeline"| training

    training -->|"defines GAN scales"| models
    training -->|"build pyramid"| functions
    training -->|"resize scales"| imresize

    %% Sampling/GAN output
    training -->|"save checkpoints"| samples

    %% Generation
    HR -->|"generate samples"| manipulate
    splicing -->|"generate samples"| splicing_funcs

    manipulate -->|"output images"| samplesHR
    splicing_funcs -->|"output images"| samplesSp

    %% Downstream tasks use pretrained models
    editing -->|"use models"| manipulate
    harmonization -->|"use models"| manipulate
    paint2image -->|"use models"| manipulate
    random_samples -->|"use models"| manipulate
    animation -->|"use models"| manipulate

    manipulate -->|"random samples"| samplesRand

    %% Evaluation
    samplesHR -->|"compute features"| inception
    samplesSp -->|"compute features"| inception
    samplesRand -->|"compute features"| inception

    inception -->|"compute SIFID"| sifid_score
    sifid_score -->|"thresholds"| SIFID_npy

    %% Click Events
    click main_train "https://github.com/cust0s/high-res-singan/blob/main/main_train.py"
    click SR "https://github.com/cust0s/high-res-singan/blob/main/SR.py"
    click HR "https://github.com/cust0s/high-res-singan/blob/main/HR.py"
    click splicing "https://github.com/cust0s/high-res-singan/blob/main/splicing.py"
    click editing "https://github.com/cust0s/high-res-singan/blob/main/editing.py"
    click harmonization "https://github.com/cust0s/high-res-singan/blob/main/harmonization.py"
    click paint2image "https://github.com/cust0s/high-res-singan/blob/main/paint2image.py"
    click random_samples "https://github.com/cust0s/high-res-singan/blob/main/random_samples.py"
    click animation "https://github.com/cust0s/high-res-singan/blob/main/animation.py"
    click SinGAN_dir "https://github.com/cust0s/high-res-singan/tree/main/SinGAN/"
    click functions "https://github.com/cust0s/high-res-singan/blob/main/SinGAN/functions.py"
    click imresize "https://github.com/cust0s/high-res-singan/blob/main/SinGAN/imresize.py"
    click models "https://github.com/cust0s/high-res-singan/blob/main/SinGAN/models.py"
    click training "https://github.com/cust0s/high-res-singan/blob/main/SinGAN/training.py"
    click manipulate "https://github.com/cust0s/high-res-singan/blob/main/SinGAN/manipulate.py"
    click splicing_funcs "https://github.com/cust0s/high-res-singan/blob/main/SinGAN/splicing_functions.py"
    click inception "https://github.com/cust0s/high-res-singan/blob/main/SIFID/inception.py"
    click sifid_score "https://github.com/cust0s/high-res-singan/blob/main/SIFID/sifid_score.py"

    %% Styles
    classDef cli fill:#9f6,stroke:#080,stroke-width:1px
    classDef library fill:#6cf,stroke:#039,stroke-width:1px
    classDef config fill:#f96,stroke:#942,stroke-width:1px
    classDef data fill:#fc9,stroke:#c60,stroke-width:1px
    classDef eval fill:#c9f,stroke:#60c,stroke-width:1px
```
