# sundongwei/sft_chag2cap architecture

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

- Interactive diagram: https://gitdiagram.com/sundongwei/sft_chag2cap
- Repository: https://github.com/sundongwei/sft_chag2cap

## Overview

##### Project Type and Purpose
- This is a full-stack deep learning research project focused on change captioning in remote sensing imagery.
- The README clearly outlines data preparation (using LEVIR-CC and Dubai-CC datasets), training, testing, and caption generation processes.
- The project implements a specific model – a lightweight, sparse focus transformer – that utilizes convolutional networks and transformer-based approaches.

##### File Structure
- Top-level files: Key training and execution scripts (train.py, test.py, caption.py, preprocess_data.py) drive the life cycle (data preparation, training, testing, inference).
- Data directories: The “data” folder holds the raw datasets for Dubai_CC and LEVIR_CC.
- Evaluation functions: The “eval_func” directory contains subdirectories for different evaluation metrics (BLEU, CIDEr, Meteor, ROUGE) that quantify model performance.
- Models: Under “models”, there are architecture files, including CNN-based networks, model decoders, and network modules (e.g. AdjustLength_net.py, CNN_Nets.py).
- Utilities: The “utils” folder provides helper routines for handling specific dataset aspects (DubaiCC, LEVIR_CC_Data) and other shared functions.

##### README for Architectural Insights
- The README explains data structure layouts, pre-processing instructions, and how each script fits into the workflow.
- It mentions required dependencies and setup tasks, some of which are necessary to support external tools (like the meteor evaluation module that requires Java).

a. Main Components:
- Data Input & Preprocessing: Represented by the raw image datasets and the preprocess_data.py script. This component parses datasets (structured as shown in the README for LEVIR-CC) and prepares token files.
- Core Model Architecture: Consisting of the transformer-based model and CNN networks (as defined in models/). Include the sub-components for feature extraction (CNN_Nets), sequence decoding (model_decoder), and any network adjustments (AdjustLength_net).
- Training Module: Embodied by train.py; indicate how the preprocessed data feeds into the learning process.
- Testing/Inference Module: Represented by test.py and caption.py, showing the transition from a trained model to caption generation.
- Evaluation Metrics: The eval_func directory represents different branches of post-processing evaluation (BLEU, CIDEr, Meteor, ROUGE).
- Utility Functions & Helpers: Under utils, label functions that help in reading data specifics and converting image pairs into the required format.

b. Relationships and Interactions:
- How preprocessed data flows into the Training Module.
- Separate the Training Module (with the network architecture) and Testing/Inference Module, showing the output model being used to generate captions.
- Link the Testing output to the Evaluation Metrics module to award scores using BLEU, CIDEr, Meteor, and ROUGE.
- Supportive flows from the “utils/” functions being used by both data preparation and model modules.

c. Architectural Patterns and Design Principles:
- Model separation: data preparation, model training, inference, and evaluation.
- That the transformer networks and CNN components follow best practices in deep learning model modularity.
- Principle of scalability – modular functions allow extending or swapping evaluation metrics without impacting core training scripts.

d. Relevant Technologies, Frameworks, and Libraries:
- PyTorch is the backbone for model implementation and training.
- Importance of external libraries for evaluation metrics (e.g., use of a Java dependency for Meteor).
- That the code utilizes typical Python environment management (requirements.txt) and version control (e.g., .gitignore, .vscode, .idea).

##### Essential Elements
- Use clear labels for each major component (e.g., “Data Preprocessing”, “Feature Extraction & Transformer Model”, “Training”, “Testing/Caption Generation”, “Evaluation Metrics”).
- Notes on external dependencies (like Java for Meteor) and any configuration/build scripts if necessary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Components
    UT["Utils"]:::utils
    DS["Datasets"]:::dataset
    PD["Preprocessing (preprocess_data.py)"]:::process
    TR["Training (train.py)"]:::process
    TI["Testing/Caption Generation (test.py, caption.py)"]:::process
    EM["Evaluation Metrics (eval_func/)"]:::eval

    %% Data Preparation Flow
    DS -->|"inputs"| PD
    UT -->|"supports"| PD

    %% Training Flow
    PD -->|"feeds"| TR
    UT -->|"assists"| TR

    %% Core Model Architecture as a Subgraph within Training
    subgraph "Core Model Architecture"
        AL["AdjustLength_net (models/AdjustLength_net.py)"]:::model
        CNN["CNN_Nets (models/CNN_Nets.py)"]:::model
        MD["Model Decoder (models/model_decoder.py)"]:::model
    end
    TR -->|"utilizes"| AL

    %% Testing and Evaluation Flow
    TR -->|"outputs trained model"| TI
    TI -->|"results evaluated by"| EM

    %% Click Events
    click DS "https://github.com/sundongwei/sft_chag2cap/tree/master/data/"
    click PD "https://github.com/sundongwei/sft_chag2cap/blob/master/preprocess_data.py"
    click AL "https://github.com/sundongwei/sft_chag2cap/blob/master/models/AdjustLength_net.py"
    click CNN "https://github.com/sundongwei/sft_chag2cap/blob/master/models/CNN_Nets.py"
    click MD "https://github.com/sundongwei/sft_chag2cap/blob/master/models/model_decoder.py"
    click TR "https://github.com/sundongwei/sft_chag2cap/blob/master/train.py"
    click TI "https://github.com/sundongwei/sft_chag2cap/blob/master/test.py"
    click TI "https://github.com/sundongwei/sft_chag2cap/blob/master/caption.py"
    click EM "https://github.com/sundongwei/sft_chag2cap/tree/master/eval_func/"
    click UT "https://github.com/sundongwei/sft_chag2cap/tree/master/utils/"

    %% Styles
    classDef dataset fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef process fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef model fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef eval fill:#ffe082,stroke:#f9a825,stroke-width:2px;
    classDef utils fill:#d1c4e9,stroke:#4527a0,stroke-width:2px;
```
