# satoshi-kosugi/masked-style-modeling architecture

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

- Interactive diagram: https://gitdiagram.com/satoshi-kosugi/masked-style-modeling
- Repository: https://github.com/satoshi-kosugi/masked-style-modeling

## Overview

##### Project type and purpose
- This is a research‐oriented deep learning project implementing “Personalized Image Enhancement Featuring Masked Style Modeling.”
- It provides a two‐step training pipeline (train1.py, train2.py), a testing/inference script (test.py), data download and degradation utilities, a dataset loader, and modular model components (content/style embeddings, transformer encoder, stylized enhancer, loss).

##### File structure
- Top level:
- data/: raw data scripts (download_from_flickr.py, degrade.py) and prebuilt train/valid pickles
- dataset/: loader.py wraps PyTorch Dataset logic
- model/: pure Python modules for each network component
- train1.py, train2.py: stage-1 and stage-2 training orchestration
- test.py: inference and evaluation
- requirements.txt, README.md
- The separation into data ingestion, dataset definition, model definition, training, testing, and utilities reveals a clear ML-pipeline pattern.

##### README for additional insights
- Two‐stage training: run train1.py then train2.py
- Test script optionally loads pretrained models
- References a paper and shows a high‐level architecture figure

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Ingestion & Preprocessing"
        data1["download_from_flickr.py"]:::data
        data2["degrade.py"]:::data
        pkl1[(train_from_flickr.pkl)]:::data
        pkl2[(valid_from_flickr.pkl)]:::data
        data1 --> pkl1
        data1 --> pkl2
        data2 --> pkl1
        data2 --> pkl2
    end

    subgraph "Dataset Loader"
        loader["loader.py"]:::dataset
    end

    pkl1 --> loader
    pkl2 --> loader

    subgraph "Model Modules"
        ce["content_embedding.py"]:::model
        se["style_embedding.py"]:::model
        te["transformer_encoder.py"]:::model
        mt["masked_token.py"]:::model
        ste["stylized_enhancer.py"]:::model
        loss["loss_pienet.py"]:::model
    end

    loader -->|"batch of images"| ce
    loader -->|"batch of images"| se
    ce -->|"content tokens"| te
    se -->|"style tokens"| mt
    te --> ste
    mt --> ste
    ste --> loss

    subgraph "Training Pipeline"
        stage1["train1.py"]:::train
        stage2["train2.py"]:::train
    end

    loader --> stage1
    stage1 --> ce
    stage1 --> se
    stage1 --> loss
    loader --> stage2
    stage2 --> ce
    stage2 --> se
    stage2 --> te
    stage2 --> ste
    stage2 --> loss

    subgraph "Testing / Inference"
        test["test.py"]:::inference
    end

    loader --> test
    test --> ce
    test --> se
    test --> te
    test --> ste

    subgraph "Utilities"
        util1["common.py"]:::util
        util2["ptcolor.py"]:::util
    end

    stage1 --> util1
    stage1 --> util2
    stage2 --> util1
    stage2 --> util2
    test --> util1
    test --> util2

    click data1 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/data/download_from_flickr.py"
    click data2 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/data/degrade.py"
    click pkl1 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/data/train_from_flickr.pkl"
    click pkl2 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/data/valid_from_flickr.pkl"
    click loader "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/dataset/loader.py"
    click ce "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/model/content_embedding.py"
    click se "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/model/style_embedding.py"
    click te "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/model/transformer_encoder.py"
    click mt "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/model/masked_token.py"
    click ste "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/model/stylized_enhancer.py"
    click loss "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/model/loss_pienet.py"
    click stage1 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/train1.py"
    click stage2 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/train2.py"
    click test "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/test.py"
    click util1 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/utils/common.py"
    click util2 "https://github.com/satoshi-kosugi/masked-style-modeling/blob/main/utils/ptcolor.py"

    classDef data fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef dataset fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef model fill:#FFE0B2,stroke:#E65100,color:#E65100
    classDef train fill:#E1BEE7,stroke:#4A148C,color:#4A148C
    classDef inference fill:#FFCDD2,stroke:#B71C1C,color:#B71C1C
    classDef util fill:#CFD8DC,stroke:#455A64,color:#455A64
```
