# ioannispol/underwatergan architecture

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

- Interactive diagram: https://gitdiagram.com/ioannispol/underwatergan
- Repository: https://github.com/ioannispol/underwatergan

## Overview

##### Main Components

- Data Preparation and Preprocessing
– Components: The data is expected to be organized in directories (e.g., "trainA", "trainB", "testA", "testB").
– Relevant directories: UnderWaterGAN_pytorch/preprocess, UnderWaterGAN_pytorch/data, and UnderWaterGAN_pytorch/datasets.
– Functionality: Creating directories, splitting and renaming datasets, and preparing image data for input to the network.

- Model Architecture and Training
– Components: This contains various models (CycleGAN, Pix2Pix, etc.) along with a number of training options and scripts.
– Relevant directories: UnderWaterGAN_pytorch/models (cycle_gan_model.py, pix2pix_model.py, etc.), UnderWaterGAN_pytorch/train.py, UnderWaterGAN_pytorch/options (train_options.py, test_options.py), and scripts (train_cyclegan.sh, train_pix2pix.sh).
– Flow: The training phase starts with loading the prepared dataset, then the model is initialized, trained using the specified options, and the network states are saved in the results directory.

- Testing / Inference Pipeline
– Components: Testing means running a forward pass through the model to generate image translations.
– Relevant files: UnderWaterGAN_pytorch/test.py and corresponding scripts (test_cyclegan.sh, etc.).
– Flow: Loading test data → applying the appropriate model (cycle_gan or test variant) → generating and storing output (e.g., HTML reports under results).

- Evaluations
– Components: The project evaluates model performance using metrics like SSIM and FID.
– Relevant directories: UnderWaterGAN_pytorch/evaluations (SSIM-py, pytorch-fid).
– Functionality: Contains separate evaluation scripts, test images, and configurations to assess the quality of image translations.

- Utility and Visualization
– Components: Helper functions and utilities for image processing, visual logging, and HTML visualization.
– Relevant directories: UnderWaterGAN_pytorch/util (html.py, image_pool.py, visualizer.py) and the integration of visdom for plotting training progress.

- Deployment / CI/CD and Containerization
– Components: Dockerfile, docker-compose files, as well as GitHub workflows are present.
– Functionality: These support containerized deployment, continuous integration (via GitHub workflows with docker-image.yml, docker-publish.yml, pylint.yml), and environment setup.

##### Relationships & Data Flow

- The Data Loader (via UnderWaterGAN_pytorch/data and datasets) feeds images into the Model.
- The Model (implemented in UnderWaterGAN_pytorch/models) connects with both Training (train.py) and Testing (test.py) modules.
- Both train and test modules use configuration options (from UnderWaterGAN_pytorch/options).
- Utilities (UnderWaterGAN_pytorch/util) are employed across data, training, and visualization.
- The Evaluation modules run once the model is trained to compute scores (SSIM, FID) with their own internal pipelines.
- Scripts in the “scripts” folder encapsulate the command-line logic to kick off training, testing, and pre-run validations.
- CI/CD workflows and container orchestration with Docker/Docker Compose facilitate deployment / experimentation cycles.

##### Architectural Patterns and Design Principles

- Separation of Concerns – Each major function (preprocessing, training, testing, evaluation) is isolated in its own directory.
- Modularity – Different models (CycleGAN, Pix2Pix, etc.) and datasets are implemented as separate modules to allow extensibility.
- Configuration Management – Training and testing options are externalized in “options”, supporting flexible experiments.
- Reusability – Utility functions and scripts encapsulate common tasks like image management and logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User / Data Provider"]:::input

    subgraph "Data Preparation & Preprocessing"
        A["Preprocessing"]:::data
        B["Data Loader"]:::data
        C["Datasets"]:::data
    end

    subgraph "Model Architecture & Training/Testing"
        D["Model Architecture"]:::model
        E["Training Pipeline"]:::train
        F["Training Options"]:::train
        G["Scripts (Train & Test)"]:::scripts
        H["Testing Pipeline"]:::test
    end

    subgraph "Evaluation"
        I["Evaluation Module"]:::eval
        J["SSIM"]:::evalDetail
        K["FID"]:::evalDetail
    end

    subgraph "Utilities"
        L["Utilities & Visualization"]:::util
    end

    subgraph "Deployment & CI/CD"
        M["Dockerfile"]:::deploy
        N["Docker Compose"]:::deploy
        O["CI/CD Workflows"]:::deploy
    end

    U --> A
    A --> B
    B --> C

    C --> E
    C --> H

    F --> E
    G --> E
    G --> H

    E --> D
    H --> D

    E --> I
    H --> I

    I --> J
    I --> K

    E --> L
    H --> L

    D --> M
    D --> N
    D --> O

    click A "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/preprocess"
    click B "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/data"
    click C "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/datasets"
    click D "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/models"
    click E "https://github.com/ioannispol/underwatergan/blob/main/UnderWaterGAN_pytorch/train.py"
    click F "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/options"
    click G "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/scripts"
    click H "https://github.com/ioannispol/underwatergan/blob/main/UnderWaterGAN_pytorch/test.py"
    click I "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/evaluations"
    click J "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/evaluations/SSIM-py"
    click K "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/evaluations/pytorch-fid"
    click L "https://github.com/ioannispol/underwatergan/tree/main/UnderWaterGAN_pytorch/util"
    click M "https://github.com/ioannispol/underwatergan/tree/main/Dockerfile"
    click N "https://github.com/ioannispol/underwatergan/blob/main/docker-compose.yml"
    click O "https://github.com/ioannispol/underwatergan/tree/main/.github/workflows"

    classDef input fill:#f2f2f2,stroke:#333,stroke-width:2px;
    classDef data fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef model fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef train fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef scripts fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef test fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef eval fill:#e2d6f3,stroke:#6f42c1,stroke-width:2px;
    classDef evalDetail fill:#f0e6ff,stroke:#9966cc,stroke-width:2px;
    classDef util fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef deploy fill:#fde2e4,stroke:#ff6b6b,stroke-width:2px;
```
