# alzayats/udnet architecture

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

- Interactive diagram: https://gitdiagram.com/alzayats/udnet
- Repository: https://github.com/alzayats/udnet

## Overview

##### Main Components
- Input Pipeline: Include the “dataset” and “data” modules (model_utils/dataset.py, model_utils/data.py) that handle image input and preprocessing.
- Model Core: Highlight the UDnet architecture (model_utils/UDnet.py) which encapsulates the central deep learning model. Note that the model is based on a U-Net-like cVAE with additional modules like Probabilistic Adaptive Instance Normalization (PAdaIN) and a statistically guided multicolour space stretch module (SGMCSS).

##### Relationships and Interactions
- Training Flow: From the data processing, illustrate the training loop components in Train.py interacting with the neural network (back-propagation, loss calculation, parameter updates).
- Inference Flow: Show a parallel path where preprocessed images are fed through UDnet (loaded with pretrained weights) via Inference.py to produce enhanced outputs.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize the separation of concerns. The model_utils folder encapsulates distinct functionalities (the core model and its supporting utilities) separate from orchestration scripts (Train.py and Inference.py).
- Reusability: The clear split between data processing, model training, and inference allows for flexible re-use and potential extension (e.g., integrating new preprocessing methods or alternative architectures).
- Single Source of Truth: The core UDnet implementation is centralized in model_utils, reducing redundancy and clarifying responsibilities.

##### Relevant Technologies and Frameworks
- External datasets: Indicate that the training path expects data from an underwater image dataset (linked in the README).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input & Preprocessing
    subgraph "Data Input & Preprocessing"
        Raw["Raw Underwater Image"]:::external
        Dataset["Data Loader: dataset"]:::preprocess
        DataPre["Preprocessing: data"]:::preprocess
        Raw -->|"feeds"| Dataset
        Dataset -->|"processes"| DataPre
    end

    %% Model Core
    DataPre -->|"to model"| UDnet["UDnet (Core Model)\n(cVAE, PAdaIN, SGMCSS)"]:::model

    %% Operational Modes
    subgraph "Operational Modes"
        Training["Training Engine (Train.py)"]:::training
        Inference["Inference Engine (Inference.py)"]:::inference
    end

    UDnet -->|"training feed"| Training
    UDnet -->|"inference feed"| Inference
    Training -->|"backpropagation"| UDnet
    Inference -->|"produces"| Output["Enhanced Image"]:::output

    %% Utility Modules
    subgraph "Utility Modules"
        ColorChange["Color Change"]:::utility
        Colournet["Colournet"]:::utility
        LabelGen["Label Gen"]:::utility
        Utils["Utils"]:::utility
    end

    ColorChange ---|"supports"| Training
    Colournet ---|"supports"| Training
    LabelGen ---|"supports"| Training
    Utils ---|"supports"| Training

    ColorChange ---|"supports"| Inference
    Colournet ---|"supports"| Inference
    LabelGen ---|"supports"| Inference
    Utils ---|"supports"| Inference

    %% Environment & Dependencies
    subgraph "Environment & Dependencies"
        PyTorch["PyTorch"]:::external
        Python["Python 3.7"]:::external
        GPU["GPU: Nvidia GeForce RTX 2080 Ti"]:::external
        ExtDataset["Underwater Dataset"]:::external
    end

    ExtDataset -->|"source"| Raw

    %% Click Events
    click Dataset "https://github.com/alzayats/udnet/blob/main/model_utils/dataset.py"
    click DataPre "https://github.com/alzayats/udnet/blob/main/model_utils/data.py"
    click UDnet "https://github.com/alzayats/udnet/blob/main/model_utils/UDnet.py"
    click ColorChange "https://github.com/alzayats/udnet/blob/main/model_utils/color_change.py"
    click Colournet "https://github.com/alzayats/udnet/blob/main/model_utils/colournet.py"
    click LabelGen "https://github.com/alzayats/udnet/blob/main/model_utils/label_gen.py"
    click Utils "https://github.com/alzayats/udnet/blob/main/model_utils/utils.py"
    click Training "https://github.com/alzayats/udnet/blob/main/Train.py"
    click Inference "https://github.com/alzayats/udnet/blob/main/Inference.py"

    %% Styles
    classDef preprocess fill:#f9e79f,stroke:#e67e22,stroke-width:2px;
    classDef model fill:#aed6f1,stroke:#3498db,stroke-width:2px;
    classDef training fill:#a9dfbf,stroke:#27ae60,stroke-width:2px;
    classDef inference fill:#f5b7b1,stroke:#e74c3c,stroke-width:2px;
    classDef utility fill:#f9e79f,stroke:#d68910,stroke-width:2px;
    classDef external fill:#d5dbdb,stroke:#7f8c8d,stroke-width:2px;
```
