# wuyanan513/pulmonary-vessel-segmentation-and-artery-vein-separation architecture

> Architecture diagram of the GitHub repository wuyanan513/pulmonary-vessel-segmentation-and-artery-vein-separation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wuyanan513/pulmonary-vessel-segmentation-and-artery-vein-separation
- Repository: https://github.com/wuyanan513/pulmonary-vessel-segmentation-and-artery-vein-separation

## Overview

##### Main Components (Top Level)
- Input Processing Layer
- Model Architecture Layer
- Training Pipeline
- Output Processing Layer

##### Detailed Component Breakdown

a. Input Layer:
- Preprocessing steps (handled by utils.py)

b. Model Architecture Layer (Primary Focus):
- Encoder Path (with 3D Contextual Transformer modules)
- Decoder Path (with 3D Contextual Transformer modules)
- Skip Connections (with Double-Attention modules)

c. Training Pipeline:
- Loss Function Component (from loss.py)
- Combination of Focal Loss and Dice Loss
- Training Loop (from main.py)
- Optimization Process

d. Output Layer:
- Segmentation Output
- Vessel Segmentation Branch
- Artery-Vein Separation Branch

##### Implementation Details

Use these symbols and conventions:
- Rounded rectangles for data representations

##### Key Architectural Elements to Highlight
- 3D CoT (Contextual Transformer) Module
- Double Attention Module
- U-Net backbone structure
- Multi-task output heads

##### Data Flow Indicators
- Input CT scan → Preprocessing → Encoder → Decoder → Segmentation Maps
- Training flow with loss calculation and backpropagation
- Validation/Inference path

Remember to:
- Use consistent styling for similar components
- Notes for key architectural innovations (transformer and attention modules)
- Relationship between the files (main.py, model.py, loss.py, utils.py) and their corresponding components in the architecture

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input_Layer
        CT_Input["CT Image Input (NC & CE)"]:::input
        Preproc["Preprocessing Module"]:::process
    end

    subgraph Model_Architecture
        direction TB
        subgraph Encoder
            Enc1["Encoder Block 1"]:::encoder
            Enc2["Encoder Block 2"]:::encoder
            Enc3["Encoder Block 3"]:::encoder
            CoT1["3D Contextual Transformer"]:::transformer
        end

        subgraph Decoder
            Dec1["Decoder Block 1"]:::decoder
            Dec2["Decoder Block 2"]:::decoder
            Dec3["Decoder Block 3"]:::decoder
            CoT2["3D Contextual Transformer"]:::transformer
        end

        subgraph Attention
            DA1["Double-Attention Module 1"]:::attention
            DA2["Double-Attention Module 2"]:::attention
        end
    end

    subgraph Training_Pipeline
        Loss["Loss Function"]:::loss
        Train["Training Loop"]:::training
        Optim["Optimizer"]:::training
    end

    subgraph Output_Layer
        VS["Vessel Segmentation"]:::output
        AV["Artery-Vein Separation"]:::output
    end

    %% Connections
    CT_Input --> Preproc
    Preproc --> Enc1
    Enc1 --> Enc2
    Enc2 --> Enc3
    Enc3 --> CoT1
    CoT1 --> Dec1
    Dec1 --> Dec2
    Dec2 --> Dec3
    Dec3 --> CoT2

    %% Skip Connections
    Enc1 -.-> DA1 -.-> Dec3
    Enc2 -.-> DA2 -.-> Dec2

    CoT2 --> VS
    CoT2 --> AV
    VS --> Loss
    AV --> Loss
    Loss --> Train
    Train --> Optim
    Optim --> |Backpropagation| Model_Architecture

    %% Click Events
    click Model_Architecture "https://github.com/wuyanan513/Pulmonary-Vessel-Segmentation-and-Artery-vein-Separation/blob/main/model.py"
    click Loss "https://github.com/wuyanan513/Pulmonary-Vessel-Segmentation-and-Artery-vein-Separation/blob/main/loss.py"
    click Train "https://github.com/wuyanan513/Pulmonary-Vessel-Segmentation-and-Artery-vein-Separation/blob/main/main.py"
    click Preproc "https://github.com/wuyanan513/Pulmonary-Vessel-Segmentation-and-Artery-vein-Separation/blob/main/utils.py"

    %% Styling
    classDef input fill:#f9f,stroke:#333
    classDef process fill:#bbf,stroke:#333
    classDef encoder fill:#afd,stroke:#333
    classDef decoder fill:#dfa,stroke:#333
    classDef transformer fill:#9cf,stroke:#333
    classDef attention fill:#fda,stroke:#333
    classDef loss fill:#faa,stroke:#333
    classDef training fill:#ddd,stroke:#333
    classDef output fill:#afa,stroke:#333

    %% Legend
    subgraph Legend
        L1["Input Processing"]:::input
        L2["Processing Module"]:::process
        L3["Encoder Block"]:::encoder
        L4["Decoder Block"]:::decoder
        L5["Transformer Module"]:::transformer
        L6["Attention Module"]:::attention
        L7["Loss Component"]:::loss
        L8["Training Component"]:::training
        L9["Output Component"]:::output
    end
```
