# cyj407/diss architecture

> Architecture diagram of the GitHub repository cyj407/diss, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cyj407/diss
- Repository: https://github.com/cyj407/diss

## Overview

##### Project type and purpose
- This is a deep‑learning research codebase implementing “DiSS,” a diffusion‑based image‑generation framework with both training/fine‑tuning pipelines and a user‑facing web interface.
- The core use cases are:
- Training diffusion models on stroke/sketch datasets
- Generating images from stroke/sketch (via CLI scripts or a Flask web UI)
- Multi‑condition editing and multimodal sampling

##### File structure
- Top‑level:
- app.py + static/ → Flask web server + front‑end
- train.py, finetune.py, sample.py, guided editing scripts → CLI entrypoints for training/sampling
- guided_diffusion/ → core diffusion model library (OpenAI guided‑diffusion fork)
- optimization/, utils/, img_process.py, resizer.py → data‑preprocessing, loss definitions, augmentation, helper modules
- diss_env.yaml → environment spec
- fig/, test‑examples/ → documentation assets & sample inputs
- Patterns:
- Layered: Web UI → CLI services → core model → GPU
- Modular: guided_diffusion as a packaged dependency, separate optimization and utils

##### Key insights from README
- Python 3.6+, PyTorch 1.4+
- Single Flask endpoint serving a canvas and invoking the model
- Training pipelines using standardized MODEL_FLAGS, DIFFUSION_FLAGS, TRAIN_FLAGS
- Checkpoints stored under ./checkpoints/
- Dependencies on external repos (guided‑diffusion, ResizeRight, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web UI Layer
    subgraph "Web UI Layer"
        UI_HTML["static/index.html"]:::web
        UI_HTML -->|serves| Flask_API
    end
    click UI_HTML "https://github.com/cyj407/diss/blob/master/static/index.html"

    %% API Server
    Flask_API["app.py (Flask API)"]:::api
    click Flask_API "https://github.com/cyj407/diss/blob/master/app.py"

    Flask_API -->|invokes inference| Inference_Pipeline

    %% Inference Pipeline
    subgraph "Inference Service"
        Inference_Pipeline["Inference Pipeline\n(sample.py, local-editing.py,\npartial-editing.py, multimodal.py)"]:::scripts
    end
    click Inference_Pipeline "https://github.com/cyj407/diss/blob/master/sample.py"
    click Inference_Pipeline "https://github.com/cyj407/diss/blob/master/local-editing.py"
    click Inference_Pipeline "https://github.com/cyj407/diss/blob/master/partial-editing.py"
    click Inference_Pipeline "https://github.com/cyj407/diss/blob/master/multimodal.py"

    Inference_Pipeline -->|uses| Preprocess
    Inference_Pipeline -->|loads model| Core_Model
    Inference_Pipeline -->|runs on| GPU
    Inference_Pipeline -->|returns image| Flask_API

    %% Training Service
    subgraph "Training & Fine-Tuning Service"
        Train_CLI["train.py"]:::scripts
        FineTune_CLI["finetune.py"]:::scripts
    end
    click Train_CLI "https://github.com/cyj407/diss/blob/master/train.py"
    click FineTune_CLI "https://github.com/cyj407/diss/blob/master/finetune.py"

    Train_CLI -->|reads| Dataset_Store
    FineTune_CLI -->|reads| Dataset_Store
    Train_CLI -->|preprocess| Preprocess
    FineTune_CLI -->|preprocess| Preprocess
    Train_CLI -->|trains| Core_Model
    FineTune_CLI -->|trains| Core_Model
    Train_CLI -->|saves| Checkpoint_Store
    FineTune_CLI -->|saves| Checkpoint_Store

    %% Core Model & Pre/Post
    Core_Model["guided_diffusion/\n(Core Model)"]:::core
    click Core_Model "https://github.com/cyj407/diss/tree/master/guided_diffusion/"
    Preprocess["Preprocess & Postprocess\n(optimization/, utils/, img_process.py,\nresizer.py)"]:::core
    click Preprocess "https://github.com/cyj407/diss/tree/master/optimization/"
    click Preprocess "https://github.com/cyj407/diss/tree/master/utils/"
    click Preprocess "https://github.com/cyj407/diss/blob/master/img_process.py"
    click Preprocess "https://github.com/cyj407/diss/blob/master/resizer.py"

    Core_Model -->|imports| Preprocess

    %% Data Stores
    Dataset_Store["Dataset Store\n(on disk)"]:::data
    Checkpoint_Store["Checkpoint Store\n(./checkpoints/)"]:::data

    %% External Resources
    GPU["GPU Compute"]:::ext
    Env["Conda Environment\n(diss_env.yaml)"]:::ext
    click Env "https://github.com/cyj407/diss/blob/master/diss_env.yaml"
    Docs["Documentation & Examples\n(fig/, test-examples/)"]:::ext
    click Docs "https://github.com/cyj407/diss/tree/master/fig/"
    click Docs "https://github.com/cyj407/diss/tree/master/test-examples/"

    %% Connections
    Dataset_Store -->|data| Preprocess
    Preprocess -->|processed data| Core_Model
    Core_Model -->|model files| Checkpoint_Store

    %% Styles
    classDef web fill:#A2DFFF,stroke:#333,stroke-width:1px
    classDef api fill:#A2FFA2,stroke:#333,stroke-width:1px
    classDef scripts fill:#FFD580,stroke:#333,stroke-width:1px
    classDef core fill:#FFB7C5,stroke:#333,stroke-width:1px
    classDef data fill:#FFE680,stroke:#333,stroke-width:1px,shape:cylinder
    classDef ext fill:#C0C0C0,stroke:#333,stroke-width:1px
```
