# rafaelbou/cyclegan_old2new_car_models architecture

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

- Interactive diagram: https://gitdiagram.com/rafaelbou/cyclegan_old2new_car_models
- Repository: https://github.com/rafaelbou/cyclegan_old2new_car_models

## Overview

##### Project type and purpose
- This is an open-source research tool implementing CycleGAN in TensorFlow. Its purpose is unpaired image-to-image translation (e.g., horses↔zebras) by training two generators and two discriminators with cycle-consistency loss.

##### File structure
- Top-level scripts:
- download_dataset.sh – fetches sample datasets (e.g. horse2zebra)
- main.py – entry point for both training and testing
- Core model code:
- model.py – builds and trains the CycleGAN (defines generators, discriminators, losses, optimizers)
- module.py – reusable neural-network building blocks (Conv, Deconv, ResNet blocks)
- ops.py – low-level TensorFlow operations (instance norm, leaky ReLU, etc.)
- Utilities and I/O:
- utils.py – data loading, image preprocessing/augmentation, result saving
- requirements.txt – Python dependencies
- Artifacts:
- imgs/ – example input/output images
- logs_old/ – previous TensorBoard event files

##### README for additional insights
- Describes how to train (`python main.py --dataset_dir=…`) and test (`--phase=test`).
- Checkpoints saved in `./checkpoint/`, logs in `./logs/`.
- Relies on TensorFlow r1.x, NumPy, SciPy, Pillow.

a. Main components
1. Data Layer
– Dataset storage (local folder, e.g. `horse2zebra/`)
– download_dataset.sh script
2. Preprocessing Layer
– utils.load_image(), utils.preprocess()
3. Model Layer
– module.py blocks
– ops.py TF layers
– model.py:
- Generator A→B, Generator B→A
- Discriminator A, Discriminator B
- Loss calculators (adversarial, cycle, identity)
- Optimizers
4. Orchestrator
– main.py: parses arguments, calls model.train() or model.test()
5. Persistence & Monitoring
– Checkpoint Manager (tf.train.Saver) → `./checkpoint/`
– TensorBoard summaries → `./logs/`
6. Output Layer
– utils.save_images() → imgs/ or test output folder

b. Relationships and data flows
- Data Layer → Preprocessing → Model Layer (input pipelines)
- Model Layer ↔ Loss functions ↔ Optimizer (training loop)
- Training loop → Checkpoint Manager (periodic saves)
- Training loop → TensorBoard summaries (metrics, images)
- Test phase: Preprocessing → Model.inference() → Output Layer

c. Architectural patterns and principles
– Modular separation:
- Reusable blocks in module.py, ops.py
- High-level orchestration in model.py and main.py
– Pipeline pattern for data ingest → transform → model
– Clear distinction between training vs. inference logic

d. Key technologies
– TensorFlow r1.x (core DL framework)
– NumPy/SciPy (data manipulation)
– Pillow (image I/O)
– TensorBoard (visualization)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        style DataLayerStroke fill:#f9f,stroke:#333,stroke-width:1px
        Download["download_dataset.sh"]:::code
        Dataset["Dataset Storage (horse2zebra/)"]:::datastore
    end

    %% Preprocessing Layer
    subgraph "Preprocessing Layer"
        Utils["utils.py"]:::code
    end

    %% Model Layer
    subgraph "Model Layer"
        Module["module.py"]:::code
        Ops["ops.py"]:::code
        Model["model.py"]:::code
    end

    %% Orchestrator
    subgraph "Orchestrator"
        Main["main.py"]:::code
    end

    %% Persistence & Monitoring
    subgraph "Persistence & Monitoring"
        Checkpoint["Checkpoint Store (./checkpoint/)"]:::datastore
        Logs["TensorBoard Logs (./logs/)"]:::datastore
        OldLogs["logs_old/"]:::datastore
    end

    %% Output Layer
    subgraph "Output Layer"
        OutputImgs["imgs/ (output images)"]:::datastore
    end

    %% Frameworks & Dependencies
    subgraph "External Frameworks"
        TF["TensorFlow r1.x"]:::framework
        NumPy["NumPy/SciPy"]:::framework
        Pillow["Pillow"]:::framework
        TB["TensorBoard"]:::framework
    end

    %% Dependencies
    Requirements["requirements.txt"]:::code

    %% Connections
    Download -->|"downloads data"| Dataset
    Dataset -->|"raw images"| Utils
    Utils -->|"preprocessed batches"| Model
    Module -->|"defines blocks"| Model
    Ops -->|"provides ops"| Model
    Model -->|"training/inference"| Main
    Main -->|"calls train()/test()"| Model
    Main -.->|"uses dependencies"| Requirements
    Model -->|"save checkpoints"| Checkpoint
    Model -->|"write summaries"| Logs
    Model -->|"test images"| OutputImgs
    LogsOld["logs_old/"]:::datastore
    LogsOld -.->|"previous logs"| TB
    Logs -->|"visualize"| TB
    Model -.->|"runs on"| TF
    Model -.->|"data ops by"| NumPy
    Utils -.->|"image I/O via"| Pillow

    %% Click Events
    click Download "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/download_dataset.sh"
    click Dataset "https://github.com/rafaelbou/cyclegan_old2new_car_models/tree/master/imgs/"
    click Utils "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/utils.py"
    click Module "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/module.py"
    click Ops "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/ops.py"
    click Model "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/model.py"
    click Main "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/main.py"
    click OldLogs "https://github.com/rafaelbou/cyclegan_old2new_car_models/tree/master/logs_old/"
    click Requirements "https://github.com/rafaelbou/cyclegan_old2new_car_models/blob/master/requirements.txt"

    %% Styles
    classDef code fill:#D6EAFE,stroke:#0B69A3,stroke-width:1px
    classDef datastore fill:#DFF2BF,stroke:#4F8A10,stroke-width:1px
    classDef framework fill:#FEEFB3,stroke:#9F6000,stroke-width:1px
```
