# cotton6/cotton-size-does-matter architecture

> Architecture diagram of the GitHub repository cotton6/cotton-size-does-matter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cotton6/cotton-size-does-matter
- Repository: https://github.com/cotton6/cotton-size-does-matter

## Overview

##### Project type and purpose
- This is an academic / open-source research codebase implementing a PyTorch-based high-resolution virtual try-on system (“COTTON”).
- It consists of (a) a large preprocessing toolkit to prepare human parsing, pose, skeleton, segmentation masks and (b) a main stage that trains or runs inference of the size-aware Clothing-Oriented Transformation Try-On Network.

##### File structure
- Top-level directories:
- code/ – contains main training/inference modules, configs, data loaders, model definitions, utilities, result exporters
- preprocessing/ – many submodules for preparing datasets: human-parsing (CIHP), cloth segmentation, cloth2skeleton, U2Net human segmentation, sleeve classifier, etc.
- TryOn_results/ – sample outputs and banner images
- root config and scripts: download_weights.sh, requirements.txt
- Within code/main/:
- configs/ – YAML files for different garment experiments
- data/1024x768/Example_top/ – precomputed human & product images, masks, parsing, poses
- model_end2end.py, main.py – orchestrate training/inference
- dataLoader.py – unifies loading of human & cloth inputs
- util/, unet/ – network parts, warping utilities, visualization

##### README for additional insights
- COTTON warps clothes via landmark-guided transformation, uses a clothing segmentation network to eliminate worn garments, supports multi‐size and tucked/untucked try-on.
- Relies on PyTorch, YAML configs, DiffAugment, Focal Loss, HTML visualizer.

##### Main components & interactions
A. Data Preprocessing (preprocessing/)
- Sub-pipelines: Human parsing (CIHP_PARSING), skeleton heatmap generation (Cloth2Skeleton), cloth segmentation (ClothSegmentation), U2Net human mask, sleeve classifier, etc.
- Outputs: standardized datasets of human images, product images, masks, parsing maps, keypoints, skeletons. Stored under code/main/data.
B. Configuration & Weight Management
- YAML configs drive experiment parameters.
- download_weights.sh fetches pretrained backbones/weights.
C. DataLoader & Augmentation (code/main/dataLoader.py + DiffAugment)
- Reads processed dataset (images + metadata), applies augmentations, bundles batches.
D. Model Forward Pass (code/main/model_end2end.py)
- Landmark-guided cloth warping module
- Clothing segmentation network module
- UNet refinements
E. Loss & Optimization
- Focal_Loss.py for classification components
- other losses (e.g., pixel L1, perceptual) embedded in main.py
F. Visualization & Evaluation
- util/html.py exports results to browsable HTML
- mean_iou_evaluate.py for parsing metrics
- final images written to code/main/result/…
G. External Frameworks & Libraries
- PyTorch, torchvision
- (In preprocessing) detectron2 for segmentation/parsing

##### Relationships and data‐flow
- Raw images → Preprocessing step(s) → Processed dataset files
- Config & weights loaded into Training/Inference pipeline
- Processed dataset → DataLoader → Model → Warping + Segmentation → Loss computation (training) or direct output (inference)
- Outputs → Visualizer/Evaluator → Result folders / HTML pages

##### Architectural patterns & design principles
- Modular pipeline separation: preprocessing modules are independent from main training/inference stage.
- Config-driven experiments: allows swapping of garment types, sizes, backbones via YAML.
- Clear separation of concerns: data loading, model definition, loss computation, visualization.

##### Key takeaways
- Essential modules by grouping related scripts under single logical blocks (e.g., “Human Parsing Preprocessor”).
- How configs/weights influence both preprocessing and the core ML pipeline.
- Make data flows explicit, from raw inputs through multiple transformations, to final outputs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Preprocessing Layer
    subgraph "Preprocessing Layer"
        CIHP["CIHP Parsing"]:::preproc
        Skeleton["Skeleton Heatmap Gen"]:::preproc
        ClothSeg["Cloth Segmentation"]:::preproc
        U2Net["U2Net Human Segmentation"]:::preproc
        Sleeve["Sleeve Classifier"]:::preproc
        BuildDS["Dataset Builder"]:::preproc
        RawData["Raw Data Tools"]:::preproc
    end

    %% Core ML Layer
    subgraph "Core ML Layer"
        Configs["YAML Configurations"]:::config
        Weights["Weight Management Script"]:::config
        DataLoader["DataLoader"]:::core
        DiffAug["DiffAugment"]:::core
        MainApp["Training/Inference Orchestrator"]:::core
        Model["End-to-End Model"]:::core
        UNetMod["UNet Refinement Modules"]:::core
        Loss["Loss Functions"]:::core
    end

    %% Output & Evaluation Layer
    subgraph "Output & Evaluation Layer"
        Eval["Mean IoU Evaluation"]:::core
        Visualizer["HTML Visualizer & Utils"]:::core
        Results["Results Storage"]:::core
        Samples["Sample Outputs & Banners"]:::core
    end

    %% External Libraries
    LIBs[/External Libs: PyTorch,\ntorchvision, detectron2/]:::ext

    %% Data Flow
    RawData --> BuildDS --> CIHP --> Skeleton --> ClothSeg --> U2Net --> Sleeve --> DataLoader
    DataLoader --> DiffAug --> MainApp
    Configs --> MainApp
    Weights --> MainApp
    LIBs --> CIHP
    LIBs --> Skeleton
    LIBs --> DataLoader
    LIBs --> Model
    MainApp --> Model --> UNetMod --> Loss
    MainApp --> Eval --> Visualizer --> Results
    MainApp --> Visualizer
    Results --> Samples

    %% Click Events
    click CIHP "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/preprocessing/CIHP_PARSING/"
    click Skeleton "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/preprocessing/Cloth2Skeleton/"
    click ClothSeg "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/preprocessing/Cloth2Segmentation/"
    click U2Net "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/preprocessing/U2Net/"
    click Sleeve "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/preprocessing/Sleeve_Classifier/"
    click BuildDS "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/preprocessing/build_dataset.py"
    click RawData "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/preprocessing/raw_Data/"
    click Configs "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/main/configs/"
    click Weights "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/download_weights.sh"
    click DataLoader "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/dataLoader.py"
    click DiffAug "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/DiffAugment_pytorch.py"
    click MainApp "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/main.py"
    click Model "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/model_end2end.py"
    click UNetMod "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/unet/unet_model.py"
    click UNetMod "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/unet/unet_parts.py"
    click Loss "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/Focal_Loss.py"
    click Eval "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/mean_iou_evaluate.py"
    click Visualizer "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/util/html.py"
    click Visualizer "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/util/visualizer.py"
    click Visualizer "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/util/util_warp.py"
    click Visualizer "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/util/pose_utils.py"
    click Visualizer "https://github.com/cotton6/cotton-size-does-matter/blob/main/code/main/util/utils.py"
    click Results "https://github.com/cotton6/cotton-size-does-matter/tree/main/code/main/result/"
    click Samples "https://github.com/cotton6/cotton-size-does-matter/tree/main/TryOn_results/"

    %% Styles
    classDef preproc fill:#FFA500,stroke:#333,stroke-width:1px
    classDef core fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef ext fill:#98FB98,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
