# senhe/flow-style-vton architecture

> Architecture diagram of the GitHub repository senhe/flow-style-vton, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/senhe/flow-style-vton
- Repository: https://github.com/senhe/flow-style-vton

## Overview

##### Project type and purpose
- This is a research-oriented, Python-based deep-learning pipeline for “virtual try-on.”
- It provides both a training subsystem (multi-stage flow and generator) and an inference (test) subsystem.

##### File structure
- Top-level folders:
– train/ → training code, data definitions, models, options, scripts
– test/ → inference code, data definitions, models, options
- Within each:
– data/ → Dataset classes & DataLoader wrappers
– models/ → network definitions (AFWM, Cloth-Flow, generator nets)
– options/ → CLI argument parsing (base_options, train_options, test_options)
– util/ → helper functions (image pools, flow utilities)
- Additional:
– train/scripts/ → shell wrappers that launch the Python training scripts in correct sequence
– train/dataset/ → raw dataset folder (VITON_traindata)
– model checkpoints (vgg19, pretrained warping/generation nets)

##### README for architectural insights
- Four training stages (PBAFN stage1 → PBAFN stage2 → PFAFN stage1 → PFAFN stage2)
- External preprocessing dependencies:
– Human parsing (e.g., via Self-Correction-Human-Parser)
– Pose estimation (OpenPose)
– DensePose heatmaps (Facebook DensePose)
- Inference requires two checkpoints: warp network + generator network

##### Main components
a. Data Sources (green):
– Raw images & clothing items (VITON_traindata)
– Human parsing masks, pose JSON, densepose heatmaps (external preprocessing)
b. Data Pipeline (yellow):
– Dataset classes → DataLoader (batching, augmentation)
c. Model Pipeline (blue):
– Stage 1: Appearance Flow Estimator
· Parser-Based (PBAFN) OR Parser-Free (PFAFN)
– Stage 2: Image Generator (parser-based or parser-free branch)
– Loss Modules (perceptual loss via VGG, adversarial loss if any)
d. Training Orchestration (purple):
– train/scripts/*.sh + train/*.py launchers
– Options parsers configure hyperparameters (learning rate, augmentation flags)
e. Inference Pipeline (teal):
– test.py driven by test/options → loads two checkpoints → applies warp network → applies generator → outputs final composite images
f. External Services (orange):
– Preprocessing tools (OpenPose, DensePose, Human-Parser)
– tensorboardX for logging

##### Relationships and interactions
Data Sources → DataLoader → Stage1 Flow Estimator → Stage2 Generator → Output Images

##### Architectural patterns & design principles
- Modular separation: data/ vs. models/ vs. options/ vs. util/
- Pipeline pattern: clearly staged training (4 sequential phases)
- Reusable configuration via options classes
- Script-based orchestration for reproducibility

##### Technologies & frameworks to annotate
- Python 3.6, PyTorch 1.x, torchvision, tensorboardX, OpenCV
- External: OpenPose, DensePose, Human-Parser

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    subgraph "External Services"
        EPS("OpenPose"):::orange
        DPS("DensePose"):::orange
        HP("Human-Parser"):::orange
    end

    %% Data Sources
    subgraph "Data Sources"
        RS("Raw Images & Clothes\n(VITON_traindata)"):::green
        PMS("Parsing Masks / Pose / DensePose"):::green
    end

    %% Data Pipeline
    subgraph "Data Pipeline"
        subgraph "Training Data Pipeline"
            AD_t("aligned_dataset.py"):::yellow
            BD_t("base_dataset.py"):::yellow
            CDL_t("custom_dataset_data_loader.py"):::yellow
            DL_t("data_loader.py"):::yellow
            IF_t("image_folder.py"):::yellow
            BDL_t("base_data_loader.py"):::yellow
        end
        subgraph "Inference Data Pipeline"
            AD_i("aligned_dataset_test.py"):::yellow
            BD_i("base_dataset.py"):::yellow
            CDL_i("custom_dataset_data_loader_test.py"):::yellow
            DL_i("data_loader_test.py"):::yellow
            IF_i("image_folder.py"):::yellow
            BDL_i("base_data_loader.py"):::yellow
        end
    end

    %% Model Pipeline
    subgraph "Model Pipeline"
        subgraph "Stage 1: Appearance Flow Estimator"
            AF_t("afwm.py"):::blue
            CF_t("afwm_cloth_flow.py"):::blue
            AF_i("afwm.py (inference)"):::blue
        end
        subgraph "Stage 2: Image Generator"
            GEN_t("networks.py"):::blue
            GEN_i("networks.py (inference)"):::blue
        end
        LOSS("Perceptual/Adversarial Loss"):::blue
    end

    %% Training Orchestration
    subgraph "Training Orchestration"
        S1("train_PBAFN_stage1_fs.sh"):::purple
        S2("train_PBAFN_e2e_fs.sh"):::purple
        S3("train_PFAFN_stage1_fs.sh"):::purple
        S4("train_PFAFN_e2e_fs.sh"):::purple
        E1("train_PBAFN_stage1_fs.py"):::purple
        E2("train_PBAFN_e2e_fs.py"):::purple
        E3("train_PFAFN_stage1_fs.py"):::purple
        E4("train_PFAFN_e2e_fs.py"):::purple
        OPT_b("base_options.py"):::purple
        OPT_t("train_options.py"):::purple
    end

    %% Inference Pipeline
    subgraph "Inference Pipeline"
        TSH("test.sh"):::purple
        TPY("test.py"):::purple
        O_b("base_options.py"):::purple
        O_t2("test_options.py"):::purple
    end

    %% Data Flow
    EPS -.->|pose JSON| PMS
    DPS -.->|densepose heatmaps| PMS
    HP -.->|parsing masks| PMS

    RS --> AD_t
    PMS --> AD_t
    AD_t --> CDL_t --> DL_t --> AF_t --> GEN_t --> OUT("Output Images"):::green
    GEN_t --> LOSS
    LOSS --> AF_t

    RS --> AD_i
    PMS --> AD_i
    AD_i --> CDL_i --> DL_i --> AF_i --> GEN_i --> OUT

    %% Orchestration flows
    S1 --> E1
    S2 --> E2
    S3 --> E3
    S4 --> E4
    E1 --> AD_t
    E2 --> GEN_t
    E3 --> AF_t
    E4 --> GEN_t
    OPT_b --> E1
    OPT_b --> E2
    OPT_b --> E3
    OPT_b --> E4
    OPT_t --> E1
    OPT_t --> E2

    TSH --> TPY
    TPY --> AD_i
    TPY --> AF_i
    TPY --> GEN_i
    O_b --> TPY
    O_t2 --> TPY

    %% Click Events
    click RS "https://github.com/senhe/flow-style-vton/blob/main/train/dataset/readme.txt"
    click AD_t "https://github.com/senhe/flow-style-vton/blob/main/train/data/aligned_dataset.py"
    click BD_t "https://github.com/senhe/flow-style-vton/blob/main/train/data/base_dataset.py"
    click CDL_t "https://github.com/senhe/flow-style-vton/blob/main/train/data/custom_dataset_data_loader.py"
    click DL_t "https://github.com/senhe/flow-style-vton/blob/main/train/data/data_loader.py"
    click IF_t "https://github.com/senhe/flow-style-vton/blob/main/train/data/image_folder.py"
    click BDL_t "https://github.com/senhe/flow-style-vton/blob/main/train/data/base_data_loader.py"
    click AD_i "https://github.com/senhe/flow-style-vton/blob/main/test/data/aligned_dataset_test.py"
    click BD_i "https://github.com/senhe/flow-style-vton/blob/main/test/data/base_dataset.py"
    click CDL_i "https://github.com/senhe/flow-style-vton/blob/main/test/data/custom_dataset_data_loader_test.py"
    click DL_i "https://github.com/senhe/flow-style-vton/blob/main/test/data/data_loader_test.py"
    click IF_i "https://github.com/senhe/flow-style-vton/blob/main/test/data/image_folder.py"
    click BDL_i "https://github.com/senhe/flow-style-vton/blob/main/test/data/base_data_loader.py"
    click AF_t "https://github.com/senhe/flow-style-vton/blob/main/train/models/afwm.py"
    click CF_t "https://github.com/senhe/flow-style-vton/blob/main/train/models/afwm_cloth_flow.py"
    click AF_i "https://github.com/senhe/flow-style-vton/blob/main/test/models/afwm.py"
    click GEN_t "https://github.com/senhe/flow-style-vton/blob/main/train/models/networks.py"
    click GEN_i "https://github.com/senhe/flow-style-vton/blob/main/test/models/networks.py"
    click S1 "https://github.com/senhe/flow-style-vton/blob/main/train/scripts/train_PBAFN_stage1_fs.sh"
    click S2 "https://github.com/senhe/flow-style-vton/blob/main/train/scripts/train_PBAFN_e2e_fs.sh"
    click S3 "https://github.com/senhe/flow-style-vton/blob/main/train/scripts/train_PFAFN_stage1_fs.sh"
    click S4 "https://github.com/senhe/flow-style-vton/blob/main/train/scripts/train_PFAFN_e2e_fs.sh"
    click E1 "https://github.com/senhe/flow-style-vton/blob/main/train/train_PBAFN_stage1_fs.py"
    click E2 "https://github.com/senhe/flow-style-vton/blob/main/train/train_PBAFN_e2e_fs.py"
    click E3 "https://github.com/senhe/flow-style-vton/blob/main/train/train_PFAFN_stage1_fs.py"
    click E4 "https://github.com/senhe/flow-style-vton/blob/main/train/train_PFAFN_e2e_fs.py"
    click OPT_b "https://github.com/senhe/flow-style-vton/blob/main/train/options/base_options.py"
    click OPT_t "https://github.com/senhe/flow-style-vton/blob/main/train/options/train_options.py"
    click TSH "https://github.com/senhe/flow-style-vton/blob/main/test/test.sh"
    click TPY "https://github.com/senhe/flow-style-vton/blob/main/test/test.py"
    click O_b "https://github.com/senhe/flow-style-vton/blob/main/test/options/base_options.py"
    click O_t2 "https://github.com/senhe/flow-style-vton/blob/main/test/options/test_options.py"

    %% Styles
    classDef green fill:#9f6,stroke:#333,stroke-width:1px
    classDef yellow fill:#fc3,stroke:#333,stroke-width:1px
    classDef blue fill:#39f,stroke:#333,stroke-width:1px
    classDef purple fill:#c3f,stroke:#333,stroke-width:1px
    classDef orange fill:#f93,stroke:#333,stroke-width:1px
```
