# xiaoxiangaq/gas-net architecture

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

- Interactive diagram: https://gitdiagram.com/xiaoxiangaq/gas-net
- Repository: https://github.com/xiaoxiangaq/gas-net

## Overview

##### Main components
- Data Handling: This includes data loaders and utility functions (data_loader_new.py and data_utils.py) along with the structured datasets described in the README (e.g., Levir-CD and Lebediv-CD with their train, validation, and test splits).
- Model Architecture: Located in the “model” directory, you have components such as CDNet_L.py (likely the main model implementation), encoder.py, and decoder.py. Together, these form the Siamese network structure, where pairs of images are processed through parallel encoders before being combined (possibly with global-aware mechanisms) and then decoded into change detection outputs.
- Training & Testing Pipelines: The training script (train.py) sets up the learning process, while test.py and tools/eval.py handle evaluation, testing, and generating results.
- Documentation & Auxiliary Files: The “doc” folder contains images of results which help in understanding output expectations, and the README provides context and citation information.

##### Relationships and interactions
- Data Flow: The pipeline starts by loading input images (time t1 and t2) using the data loader (data_loader_new.py / data_utils.py), which organizes the data according to the dataset structure mentioned in the README.
- Model Processing (Siamese Architecture): The input data is fed into the encoder modules (from encoder.py) to extract features for each time step. The CDNet_L.py likely orchestrates the combination of these features, possibly via global-aware mechanisms, and passes them to the decoder module (decoder.py) to generate change detection maps.
- Training Loop: The training process in train.py integrates the model, data loaders, and loss functions (not explicitly detailed in the file names but assumed to be part of the training flow). It uses the PyTorch framework to update the model parameters.
- Evaluation: After the model is trained, test.py and tools/eval.py evaluate the model on test datasets, generating change detection results and possibly comparing them against ground truth.

##### Architectural patterns and design principles
- Modular Design: The separation into distinct modules for data loading, model architecture (split further into encoder, decoder, and overall network), training, and evaluation promotes a clean, maintainable codebase.
- Siamese Architecture: The architecture inherently processes pairs of images simultaneously to capture changes, emphasizing parallel data flows in feature extraction.
- Pipeline Separation: There is a clear delineation between the training phase (train.py) and evaluation/testing phases (test.py, tools/eval.py), crucial for clear system design.

##### Instructing the Principal Software Engineer
- Use of PyTorch for the deep learning components by mentioning it near the Model and Training blocks.
- Separation of concerns by grouping associated files (for instance, group CDNet_L.py, encoder.py, and decoder.py under “Model Architecture”).
- Provide annotations regarding any intermediate representations or preprocessing steps that might be performed on the remote sensing data.
- Modularity and potential extensibility of the design so that future changes (like new dataset integration or model variations) can be managed efficiently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Handling Subgraph
    subgraph "Data Handling"
        Loader1("Data Loader (data_loader_new.py)"):::data
        Loader2("Data Utils (data_utils.py)"):::data
        DataCombined("Combined Data Loader"):::data
        Loader1 --> DataCombined
        Loader2 --> DataCombined
    end

    %% Model Architecture Subgraph
    subgraph "Model Architecture (PyTorch)"
        subgraph "Encoders"
            Encoder1("Encoder (Time t1)"):::model
            Encoder2("Encoder (Time t2)"):::model
        end
        Fusion("Global-Aware Feature Fusion"):::model
        Decoder("Decoder"):::model
        ChangeOutput("Change Detection Map"):::model

        Encoder1 --> Fusion
        Encoder2 --> Fusion
        Fusion --> Decoder
        Decoder --> ChangeOutput
    end

    %% Training Pipeline Subgraph
    subgraph "Training Pipeline"
        Train("Training Loop"):::train
    end

    %% Testing and Evaluation Pipeline Subgraph
    subgraph "Testing/Evaluation Pipeline"
        Test("Testing"):::train
        Evaluation("Evaluation"):::train
    end

    %% Documentation & Auxiliary Files Subgraph
    subgraph "Documentation"
        Doc("Documentation (doc)"):::doc
        Readme("README"):::doc
    end

    %% Connections between subgraphs
    DataCombined --> Encoder1
    DataCombined --> Encoder2
    DataCombined --> Train
    DataCombined --> Test
    DataCombined --> Evaluation
    Train -->|"updates"| Fusion
    Decoder -->|"inference"| Test
    Decoder -->|"inference"| Evaluation

    %% Styles
    classDef data fill:#add8e6,stroke:#333,stroke-width:2px,color:#000;
    classDef model fill:#90ee90,stroke:#333,stroke-width:2px,color:#000;
    classDef train fill:#ffcc99,stroke:#333,stroke-width:2px,color:#000;
    classDef doc fill:#d3d3d3,stroke:#333,stroke-width:2px,color:#000;

    %% Click Events
    click Loader1 "https://github.com/xiaoxiangaq/gas-net/blob/main/data_loader_new.py"
    click Loader2 "https://github.com/xiaoxiangaq/gas-net/blob/main/data_utils.py"
    click Encoder1 "https://github.com/xiaoxiangaq/gas-net/blob/main/model/encoder.py"
    click Encoder2 "https://github.com/xiaoxiangaq/gas-net/blob/main/model/encoder.py"
    click Fusion "https://github.com/xiaoxiangaq/gas-net/blob/main/model/CDNet_L.py"
    click Decoder "https://github.com/xiaoxiangaq/gas-net/blob/main/model/decoder.py"
    click Train "https://github.com/xiaoxiangaq/gas-net/blob/main/train.py"
    click Test "https://github.com/xiaoxiangaq/gas-net/blob/main/test.py"
    click Evaluation "https://github.com/xiaoxiangaq/gas-net/blob/main/tools/eval.py"
    click Doc "https://github.com/xiaoxiangaq/gas-net/tree/main/doc"
    click Readme "https://github.com/xiaoxiangaq/gas-net/blob/main/README.md"
```
