# jiayi-fu/ipc-dehaze architecture

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

- Interactive diagram: https://gitdiagram.com/jiayi-fu/ipc-dehaze
- Repository: https://github.com/jiayi-fu/ipc-dehaze

## Overview

##### Main Components
- Core Library (basicsr package):
- Architectural Modules (basicsr/archs): Contains various network definitions such as dehaze architectures, VQGAN (generator and discriminator), predictor, and critic networks.
- Data Handling (basicsr/data): Functions and classes for loading image datasets, performing transformations, and handling both paired and single image datasets.
- Loss Computation (basicsr/losses): Implementations of loss functions and utilities to compute and manage losses during training.
- Model and Training Utilities (basicsr/models): Base classes and definitions for models, schedulers, and specific implementations for the predictor and critic models. Also includes training scripts (basicsr/train.py) and testing (basicsr/test.py).
- Utility Functions (basicsr/utils): Helper modules for various tasks (like file management, logging, image processing, and parallel decoding) which ensure modularity and reusability.

- Inference & Execution:
- Inference script (inference.py) that ties together the models and data for running the dehazing process.

- Scripts and Tools:
- Data Preparation Scripts (scripts/data_preparation): Scripts to download datasets, create LMDBs, extract images, and prepare metadata.
- Metric Evaluation Scripts (scripts/metrics): Tools to compute evaluation metrics such as FID, PSNR, SSIM, etc.
- Model Conversion and MATLAB scripts: For converting model formats and additional image processing/post-processing steps.

##### Relationships and Interactions
- Data Flow:
- Input images and related data (datasets: rgb_500, depth_500, etc.) are prepared externally (using the data_preparation scripts) and fed into the system.
- In the inference pipeline, datasets are processed by the Data Handling modules, passed through the network architectures in the archs submodule (predictor and critic networks) and trigger the dehazing functions.

- Dependency Links:
- The models are built using the architectures, and losses are computed during training using the loss modules.
- Utility functions support multiple modules (e.g., logger, file_client) across the entire pipeline.
- External pretrained model checkpoints (for VQGAN, Predictor, Critic) are loaded and utilized in the inference and training phases.

- Training and Evaluation:
- The training pipeline (triggered by basicsr/train.py) integrates the dataset management, model building, and losses.
- Evaluation scripts in the scripts/metrics directory provide quantitative assessments of the dehazing performance, taking output from inference/training pipelines.

##### Architectural Patterns & Design Principles
- Modular Separation: The system is naturally divided into modules (archs, data, losses, models, utils) promoting reusability and clear separation of concerns.
- Pipeline Flow: There is a clear sequential data flow from dataset preparation to model forward passes to loss calculations and backpropagation (during training) or inference.
- Extensibility: The design allows for additional architectures, data transforms, or loss functions to be easily plugged into the system by following the existing folder structure.

##### Relevant Technologies, Frameworks, or Libraries
- PyTorch: Primary deep learning framework.
- Conda: For environment management as specified.
- Dependencies as specified in requirements.txt (likely including numpy, opencv, etc.).
- MATLAB scripts exist for back-projection and other image processing steps not covered by Python, which should be represented as an external processing block.

- Clear labels for each main component:
- Data Preparation (scripts/data_preparation)
- Core Model Components (basicsr: archs, models, losses, utils)
- Inference Pipeline (inference.py)
- Evaluation & Metrics (scripts/metrics)
- Pre-trained Models & External Assets (datasets and pretrained_models directories as described in the README)
- From “Datasets” to “Data Loader” in basicsr/data, then into “Network Architectures” (Predictor and Critic) inside the archs directory.

##### Additional Detailing
- Incorporate annotations for key iterations or steps in the predictor–critic iterative decoding process.
- Optionally, include reference to the paper (CVPR2025) and key performance indicators (like the quantitative evaluation results) if further clarity is needed for stakeholders.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Preparation & External Assets
    subgraph "Data Preparation & External Assets"
        Datasets("Raw Datasets"):::external
        DP("Data Preparation Scripts"):::scripts
    end

    %% Core Library (basicsr)
    subgraph "Core Library (basicsr)"
        direction TB
        DH("Data Handling"):::core
        NA("Network Architectures"):::core
        LC("Loss Computation"):::core
        subgraph "Model & Training Utilities"
            MD("Model Definitions"):::core
            TP("Training Process"):::core
            TSP("Testing Process"):::core
        end
        UF("Utility Functions"):::core
    end

    %% Inference & Evaluation
    subgraph "Inference & Evaluation"
        IP("Inference Pipeline"):::scripts
        ME("Metric Evaluation"):::scripts
    end

    %% Additional Tools
    subgraph "Additional Tools"
        MC("Model Conversion Tools"):::scripts
        MS("MATLAB Scripts"):::scripts
    end

    %% Data Flow Connections
    Datasets -->|"feeds"| DP
    DP -->|"prepares"| DH
    DH -->|"supplies"| NA
    NA -->|"generates features for"| MD
    MD -->|"triggers"| TP
    LC -->|"computesLoss"| TP
    UF -->|"supports"| TP
    TP -->|"validates"| TSP
    TP -->|"informs"| IP
    IP -->|"assessedBy"| ME

    %% Click Events
    click DP "https://github.com/jiayi-fu/ipc-dehaze/tree/main/scripts/data_preparation/"
    click DH "https://github.com/jiayi-fu/ipc-dehaze/tree/main/basicsr/data/"
    click NA "https://github.com/jiayi-fu/ipc-dehaze/tree/main/basicsr/archs/"
    click LC "https://github.com/jiayi-fu/ipc-dehaze/tree/main/basicsr/losses/"
    click MD "https://github.com/jiayi-fu/ipc-dehaze/tree/main/basicsr/models/"
    click TP "https://github.com/jiayi-fu/ipc-dehaze/blob/main/basicsr/train.py"
    click TSP "https://github.com/jiayi-fu/ipc-dehaze/blob/main/basicsr/test.py"
    click UF "https://github.com/jiayi-fu/ipc-dehaze/tree/main/basicsr/utils/"
    click IP "https://github.com/jiayi-fu/ipc-dehaze/blob/main/inference.py"
    click ME "https://github.com/jiayi-fu/ipc-dehaze/tree/main/scripts/metrics/"
    click MC "https://github.com/jiayi-fu/ipc-dehaze/tree/main/scripts/model_conversion/"
    click MS "https://github.com/jiayi-fu/ipc-dehaze/tree/main/scripts/matlab_scripts/"

    %% Styles
    classDef core fill:#f9c,stroke:#333,stroke-width:2px;
    classDef scripts fill:#9cf,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px;
```
