# cs-chan/artgan architecture

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

- Interactive diagram: https://gitdiagram.com/cs-chan/artgan
- Repository: https://github.com/cs-chan/artgan

## Overview

##### Project type and purpose
- This is a research‐oriented machine-learning codebase centered on Generative Adversarial Networks (GANs) for artwork and natural image synthesis (“ArtGAN”), plus a companion classification experiment (“ICIP-16”) and the associated WikiArt dataset.
- It bundles (a) data ingestion and preprocessing, (b) custom Python-based GAN model definitions and training scripts, (c) sample generation scripts, (d) evaluation utilities (Inception score), and (e) a set of Caffe‐based fine-tuning experiments for painting classification.

##### File structure
- Top‐level folders:
- ArtGAN/ – core GAN code
- ICIP-16/ – classification code and paper reference
- “WikiArt Dataset” – raw image files and CSV/txt metadata
- data/ – Caffe mean files and helper scripts for classification
- models/ – Caffe deploy/solver prototxts and train/test shell scripts
- Within ArtGAN/:
- data/ – data_loader.py, multiple ingest_*.py for CIFAR, CUB, Flower, STL, WikiArt; tf_reader for TFRecord ingestion
- nn/ – custom neural-net building blocks (layers, activations, ops)
- models/ – readme (placeholder for future model zoo)
- utils/ – inception_score, utility functions (e.g., saving samples)
- top-level scripts (Artist128GANAE.py, CIFAR64GANAEtrick.py, etc.) – entrypoints for training different conditional GAN variants
- Configuration: requirements.in/requirements.txt for Python dependencies; Caffe prototxts and shell scripts under models/ for classification.

##### README for additional insights
- Confirms three deliverables: (1) WikiArt Dataset release, (2) “Improved ArtGAN” for conditional synthesis (published in TIP ’19), (3) “Deep Convolutional Network for Fine-art Paintings Classification” (ICIP ’16).

1. Data Sources
– WikiArt images + metadata
– CIFAR-10, CUB-200, Flower-102, STL-10
2. Data Ingestion & Preprocessing
– ingest_*.py scripts → raw images → TFRecords via tf_reader
3. Model Definition
– custom Python nn package (layers, activations, ops)
– GAN architectures (128×128 autoencoder variants)
4. Training Pipeline
– top-level Python scripts (Artist128GANAE.py, etc.)
– hyperparameter configurations
5. Sample Generation
– sample scripts (Artist128GANAEsample.py, etc.)
6. Evaluation
– inception_score module → quality metrics
7. External Tools
– TensorFlow (for TFRecords + training)
– Caffe (for ICIP-16 classification; uses deploy.prototxt, solver.prototxt, shell scripts)
– Data Sources → Data Ingestion → TFRecords → Training Pipeline → Model Checkpoints
– Model Checkpoints → Sample Generation → Generated Images
– Generated Images → Evaluation → Metrics
– For ICIP-16 branch: Data Sources → Caffe mean protos → Caffe Training → Classification Results
c. Architectural patterns & principles
– Modular separation: data, model, training, evaluation, utilities
– Script-based CLI interfaces for each experiment
– Custom neural-net library to decouple model logic from backend (TensorFlow)
– Reuse of external frameworks (TensorFlow for GANs, Caffe for classification)
d. Key technologies & frameworks
– Python 3.x, TensorFlow (implicit via tf_reader), Caffe
– Bash scripts for Caffe training/test
– Custom Python modules (under nn/ and utils/)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Sources
    subgraph "Data Sources" 
        DS1["WikiArt Dataset"]:::data
        DS2["CIFAR-10 Images"]:::data
        DS3["CUB-200 Images"]:::data
        DS4["Flower-102 Images"]:::data
        DS5["STL-10 Images"]:::data
    end

    %% Data Ingestion & Preprocessing
    subgraph "Data Ingestion & Preprocessing"
        IN1["ingest_cifar10.py"]:::data
        IN2["ingest_cub200.py"]:::data
        IN3["ingest_flower102.py"]:::data
        IN4["ingest_stl10.py"]:::data
        IN5["tf_reader.py"]:::data
        IN6["data_loader.py"]:::data
    end

    %% TFRecords artifact
    TF["TFRecords"]:::data

    %% Model Definition
    subgraph "Model Definition"
        MD["nn package"]:::model
    end

    %% GAN Training Pipeline
    subgraph "GAN Training Pipeline"
        TP1["Artist128GANAE.py"]:::training
        TP2["CIFAR64GANAEtrick.py"]:::training
        TP3["CUB128GANAE.py"]:::training
        TP4["Flower128GANAE.py"]:::training
        TP5["STL128GANAE.py"]:::training
        TP6["Genre128GANAE.py"]:::training
        TP7["Style128GANAE.py"]:::training
    end

    %% Sample Generation
    subgraph "Sample Generation"
        SG1["Artist128GANAEsample.py"]:::training
        SG2["CIFAR64GANAEsample.py"]:::training
        SG3["CUB128GANAEsample.py"]:::training
        SG4["Flower128GANAEsample.py"]:::training
        SG5["STL128GANAEsample.py"]:::training
        SG6["Genre128GANAEsample.py"]:::training
        SG7["Style128GANAEsample.py"]:::training
    end

    %% Generated Images artifact
    GI["Generated Images"]:::data

    %% Evaluation
    subgraph "Evaluation"
        EV["inception_score.py"]:::evaluation
    end
    MET["Metrics"]:::evaluation

    %% Classification Track
    DS1 -->|images| IN5
    DS2 -->|images| IN1
    DS3 -->|images| IN2
    DS4 -->|images| IN3
    DS5 -->|images| IN4

    IN1 -->|raw→TFRecords| IN5
    IN2 -->|raw→TFRecords| IN5
    IN3 -->|raw→TFRecords| IN5
    IN4 -->|raw→TFRecords| IN5
    IN5 -->|reads| IN6
    IN6 -->|outputs| TF
    TF -->|feeds| MD
    MD -->|defines| TP1
    MD -->|defines| TP2
    MD -->|defines| TP3
    MD -->|defines| TP4
    MD -->|defines| TP5
    MD -->|defines| TP6
    MD -->|defines| TP7

    TP1 -->|checkpoints| TP1
    TP2 -->|checkpoints| TP2
    TP3 -->|checkpoints| TP3
    TP4 -->|checkpoints| TP4
    TP5 -->|checkpoints| TP5
    TP6 -->|checkpoints| TP6
    TP7 -->|checkpoints| TP7

    TP1 -->|samples| SG1
    TP2 -->|samples| SG2
    TP3 -->|samples| SG3
    TP4 -->|samples| SG4
    TP5 -->|samples| SG5
    TP6 -->|samples| SG6
    TP7 -->|samples| SG7

    SG1 -->|images| GI
    SG2 -->|images| GI
    SG3 -->|images| GI
    SG4 -->|images| GI
    SG5 -->|images| GI
    SG6 -->|images| GI
    SG7 -->|images| GI

    GI -->|evaluate| EV
    EV -->|score| MET

    %% Classification Experiment (ICIP-16)
    DS1 -->|images| CDP
    subgraph "Caffe Data Preparation"
        DP1["artist_mean.binaryproto"]:::data
        DP2["classes"]:::data
        DP3["make_imagenet_mean.sh"]:::data
        DP4["genre_mean.binaryproto"]:::data
        DP5["classes"]:::data
        DP6["make_imagenet_mean.sh"]:::data
        DP7["style_mean.binaryproto"]:::data
        DP8["classes"]:::data
        DP9["make_imagenet_mean.sh"]:::data
    end

    DP1 -->|binaryproto| CM
    DP2 -->|labels| CM
    DP3 -->|script| CM
    DP4 -->|binaryproto| CM
    DP5 -->|labels| CM
    DP6 -->|script| CM
    DP7 -->|binaryproto| CM
    DP8 -->|labels| CM
    DP9 -->|script| CM

    subgraph "Caffe Models & Training"
        CM1["alexnet_finetune_artist"]:::training
        CM2["alexnet_finetune_genre"]:::training
        CM3["alexnet_finetune_style"]:::training
    end
    CM1 -->|fine-tune| CR
    CM2 -->|fine-tune| CR
    CM3 -->|fine-tune| CR
    CR["Classification Results"]:::evaluation

    %% External Frameworks
    subgraph "External Frameworks"
        EF1["TensorFlow"]:::external
        EF2["Caffe"]:::external
    end

    IN5 -->|TFRecords API| EF1
    MD -->|TensorFlow ops| EF1
    TP1 -->|training| EF1
    CM1 -->|deploy/solver prototxt| EF2
    CM2 -->|deploy/solver prototxt| EF2
    CM3 -->|deploy/solver prototxt| EF2

    %% Click Events
    click DS1 "https://github.com/cs-chan/artgan/tree/master/WikiArt Dataset/"
    click IN1 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/data/ingest_cifar10.py"
    click IN2 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/data/ingest_cub200.py"
    click IN3 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/data/ingest_flower102.py"
    click IN4 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/data/ingest_stl10.py"
    click IN5 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/data/tf_reader.py"
    click IN6 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/data/data_loader.py"
    click MD "https://github.com/cs-chan/artgan/blob/master/ArtGAN/nn/__init__.py"
    click TP1 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Artist128GANAE.py"
    click TP2 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/CIFAR64GANAEtrick.py"
    click TP3 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/CUB128GANAE.py"
    click TP4 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Flower128GANAE.py"
    click TP5 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/STL128GANAE.py"
    click TP6 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Genre128GANAE.py"
    click TP7 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Style128GANAE.py"
    click SG1 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Artist128GANAEsample.py"
    click SG2 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/CIFAR64GANAEsample.py"
    click SG3 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/CUB128GANAEsample.py"
    click SG4 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Flower128GANAEsample.py"
    click SG5 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/STL128GANAEsample.py"
    click SG6 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Genre128GANAEsample.py"
    click SG7 "https://github.com/cs-chan/artgan/blob/master/ArtGAN/Style128GANAEsample.py"
    click EV "https://github.com/cs-chan/artgan/blob/master/ArtGAN/utils/inception_score.py"
    click DP1 "https://github.com/cs-chan/artgan/blob/master/data/artist/artist_mean.binaryproto"
    click DP2 "https://github.com/cs-chan/artgan/tree/master/data/artist/classes"
    click DP3 "https://github.com/cs-chan/artgan/blob/master/data/artist/make_imagenet_mean.sh"
    click DP4 "https://github.com/cs-chan/artgan/blob/master/data/genre/genre_mean.binaryproto"
    click DP5 "https://github.com/cs-chan/artgan/tree/master/data/genre/classes"
    click DP6 "https://github.com/cs-chan/artgan/blob/master/data/genre/make_imagenet_mean.sh"
    click DP7 "https://github.com/cs-chan/artgan/blob/master/data/style/style_mean.binaryproto"
    click DP8 "https://github.com/cs-chan/artgan/tree/master/data/style/classes"
    click DP9 "https://github.com/cs-chan/artgan/blob/master/data/style/make_imagenet_mean.sh"
    click CM1 "https://github.com/cs-chan/artgan/tree/master/models/alexnet_finetune_artist/"
    click CM2 "https://github.com/cs-chan/artgan/tree/master/models/alexnet_finetune_genre/"
    click CM3 "https://github.com/cs-chan/artgan/tree/master/models/alexnet_finetune_style/"
    click DS1 "https://github.com/cs-chan/artgan/blob/master/ICIP-16/README.md"

    %% Styles
    classDef data fill:#cce5ff,stroke:#000;
    classDef model fill:#d4edda,stroke:#000;
    classDef training fill:#fff3cd,stroke:#000;
    classDef evaluation fill:#f8d7da,stroke:#000;
    classDef external fill:#e2e3e5,stroke:#000;
```
