# xbsj-cool/caspfuse architecture

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

- Interactive diagram: https://gitdiagram.com/xbsj-cool/caspfuse
- Repository: https://github.com/xbsj-cool/caspfuse

## Overview

##### Main Components
- Core Models: Under the "models" directory you have several key files:
- base_model.py (common base class functionality)
- cycle_gan_model.py (implements a CycleGAN-based image fusion model)
- pix2pix_model.py (implements a Pix2Pix-based image fusion model)
- networks.py (defines the network layers and structures)
- Configuration and Options: The "options" folder contains configuration files for different modes:
- base_options.py (common configuration shared by training and testing)
- train_options.py (specific parameters for training)
- test_options.py (specific parameters for testing)
- Utility Functions: The "util" directory provides supportive functions:
- get_data.py (probably for loading and preprocessing data)
- visualizer.py (for visualizing training progress/results)
- image_pool.py, html.py, and util.py (other helper scripts)
- Execution Scripts: The root-level scripts for executing the program:
- test.py (for testing, as shown in the README)
- (Note: Although the README shows “train.py” for training, it might be generated similarly or was omitted from the file tree.)
- Assets/Documentation:
- README.md (contains project description, external datasets, and citations)

##### Relationships and Interactions
- Training & Testing Scripts: The execution scripts (train.py/test.py) load configuration from the options modules and then instantiate and use one of the models from the models directory.
- Models Use Underlying Networks: The models build on the implementations in networks.py. The base_model.py provides shared functionalities which the specialized models (cycle_gan_model.py and pix2pix_model.py) extend.
- Utilities Integration: The util modules supply functions for data loading (get_data.py), visualization (visualizer.py), and additional operations (such as managing an image pool), which are likely integrated during training/testing to process images and display results.
- Data Sources: The project is designed to fuse images from multiple datasets (RoadScene, M3FD, PET-MRI) as indicated in the README. Although these data sources are external, they serve as input to the deep learning pipeline.

##### Architectural Patterns and Design Principles
- Modularity: The project is clearly modular with separation into "models," "options," and "util" directories.
- Configuration-Driven Execution: Different options classes (for training and testing) promote customization without modifying model code.
- Inheritance/Polymorphism: The use of a base model from which specialized fusion models inherit common behavior.
- Reusability: Utilities and network components are designed to be reused across different experiments or model variants.
- Clear Separation Between Core Logic and Helpers: This separation helps in isolating network architectures from data management and visualization logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Sources
    subgraph "External Data Sources"
        RS("RoadScene"):::external
        M3FD("M3FD"):::external
        PET("PET-MRI"):::external
    end

    %% Documentation
    subgraph "Documentation"
        DOC("Documentation/Framework Diagram"):::external
    end

    %% Configuration Layer
    subgraph "Configuration"
        baseOptions("Base Options"):::config
        trainOptions("Train Options"):::config
        testOptions("Test Options"):::config
    end

    %% Models Layer
    subgraph "Models"
        baseModel("Base Model"):::models
        cycleGan("CycleGAN Model"):::models
        pix2pix("Pix2Pix Model"):::models
        networks("Networks"):::models
    end

    %% Utilities Layer
    subgraph "Utilities"
        dataLoader("Data Loader"):::utility
        visualizer("Visualization"):::utility
        imagePool("Image Pool"):::utility
        htmlUtil("HTML Utility"):::utility
        miscUtil("Misc Utility"):::utility
    end

    %% Execution Layer
    subgraph "Execution"
        testScript("Test Script"):::execution
    end

    %% Data Flow Connections
    RS -->|"feeds"| dataLoader
    M3FD -->|"feeds"| dataLoader
    PET  -->|"feeds"| dataLoader

    dataLoader -->|"preprocesses"| baseModel

    %% Configuration Flow
    baseOptions -->|"configures"| baseModel
    trainOptions -->|"configures"| baseModel
    testOptions -->|"configures"| baseModel

    baseOptions -->|"defines network"| networks
    testOptions -->|"defines network"| networks
    trainOptions -->|"defines network"| networks

    %% Model Inheritance and Dependency
    baseModel -->|"extends"| cycleGan
    baseModel -->|"extends"| pix2pix
    cycleGan -->|"builds upon"| networks
    pix2pix -->|"builds upon"| networks

    %% Execution Script Flow
    testScript -->|"loads config"| testOptions
    testScript -->|"invokes"| dataLoader
    testScript -->|"selects model"| cycleGan
    testScript -->|"selects model"| pix2pix
    testScript -->|"triggers"| visualizer
    testScript -->|"utilizes"| miscUtil
    testScript -->|"utilizes"| imagePool
    testScript -->|"utilizes"| htmlUtil

    %% Documentation reference
    DOC ---|"refers to"| baseModel

    %% Styling Classes
    classDef models fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef config fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef utility fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef execution fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#F0E68C,stroke:#000,stroke-width:2px;

    %% Click Events
    click baseModel "https://github.com/xbsj-cool/caspfuse/blob/main/models/base_model.py"
    click cycleGan "https://github.com/xbsj-cool/caspfuse/blob/main/models/cycle_gan_model.py"
    click pix2pix "https://github.com/xbsj-cool/caspfuse/blob/main/models/pix2pix_model.py"
    click networks "https://github.com/xbsj-cool/caspfuse/blob/main/models/networks.py"

    click baseOptions "https://github.com/xbsj-cool/caspfuse/blob/main/options/base_options.py"
    click trainOptions "https://github.com/xbsj-cool/caspfuse/blob/main/options/train_options.py"
    click testOptions "https://github.com/xbsj-cool/caspfuse/blob/main/options/test_options.py"

    click dataLoader "https://github.com/xbsj-cool/caspfuse/blob/main/util/get_data.py"
    click visualizer "https://github.com/xbsj-cool/caspfuse/blob/main/util/visualizer.py"
    click imagePool "https://github.com/xbsj-cool/caspfuse/blob/main/util/image_pool.py"
    click htmlUtil "https://github.com/xbsj-cool/caspfuse/blob/main/util/html.py"
    click miscUtil "https://github.com/xbsj-cool/caspfuse/blob/main/util/util.py"

    click testScript "https://github.com/xbsj-cool/caspfuse/blob/main/test.py"
    click DOC "https://github.com/xbsj-cool/caspfuse/blob/main/README.md"
```
