# debeshjha/mdnet architecture

> Architecture diagram of the GitHub repository debeshjha/mdnet, 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/debeshjha/mdnet
- Repository: https://github.com/debeshjha/mdnet

## Overview

##### Main Components
- Input & Data Preprocessing: Represent the CT scan images that feed into the system. Although there is no explicit “preprocess” file, input handling is implied.
- Encoder (MiT-B2): This is handled in the mit.py module. It processes input images and extracts multi-scale feature maps (F1, F2, F3, and F4).
- Multi-scale Feature Enhancement Module: Although not isolated in a single file, this functionality is integrated into the network (possibly within model.py) and connects encoder outputs to the decoders using dilated blocks.
- Multiple Decoders: There are multiple decoders (the iterative refinement process) that take encoder features plus the outputs/feature maps from the previous decoder and even the predicted segmentation masks to refine the segmentation. This pipeline is implemented through the model.py and cbam.py modules (cbam likely provides an attention mechanism).
- Training and Testing Pipelines: Represented by train.py and test.py, these scripts manage the model training loop, loss computation, and evaluation.
- Utility and Evaluation Modules: Files like metrics.py and utils.py handle performance metrics (e.g., dice similarity coefficient) and likely other helper functions. The heatmap.py is used for visualizing results.

##### Out Relationships/Interactions
- Feature maps flowing into one or more Multi-scale Feature Enhancement blocks (highlighted as “Dilated Blocks / Spatial Attention Mechanism”) where each connects to a corresponding decoder.
- Finally, link the last decoder to the Final Segmentation Output.
- Optionally, add an evaluation branch showing that outputs feed into metrics calculations (metrics.py) and visualization routines (heatmap.py).

##### Architectural Patterns & Important Elements
- Encoder-decoder pattern, with an added note on the iterative refinement (stacked decoders with feature and mask feedback loops).
- Attention mechanisms (likely with the CBAM module) even if implemented in conjunction with the decoders.
- That the decoders are interconnected, not isolated – each subsequent decoder uses both encoder features and outputs from the previous decoder to refine the segmentation.

- Even if the project is research-focused and relatively self-contained (no external microservices or complex networking), aim to capture each stage from the point of data ingestion, through the multi-stage processing, to the final outputs and evaluation.
- For a full-stack engineering perspective, although it’s a standalone research code base, making the separation clear between “Model Definition”, “Training/Testing Pipeline”, and “Evaluation/Visualization” will help in understanding and maintaining the code.

- Connections where feedback or data reuse occurs (e.g., previous decoder outputs into subsequent decoders).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input & Preprocessing Layer
    subgraph "Data Input & Preprocessing"
        Input["Input CT Image"]:::core
    end

    %% Model Architecture Layer
    subgraph "Model Architecture"
        Encoder["MiT-B2 Encoder"]:::core
        FS["Multi-scale Feature Enhancement"]:::core
        D1["Decoder 1"]:::core
        D2["Decoder 2"]:::core
        Output["Final Segmentation Mask"]:::core
    end

    %% Pipelines and Utilities Layer
    subgraph "Pipelines and Utilities"
        Train["Training Loop"]:::utils
        Test["Testing Pipeline"]:::utils
        Metrics["Performance Metrics"]:::utils
        Util["Utility Functions"]:::utils
        Heatmap["Heatmap Visualization"]:::utils
    end

    %% Data Flow Connections
    Input -->|"InputImage"| Encoder
    Encoder -->|"ExtractedFeatures(F1-F4)"| FS
    FS -->|"EnhancedFeatures"| D1
    D1 -->|"RefinementOutput"| D2
    D2 -->|"FinalSegmentation"| Output

    %% Additional Pipeline Flow
    Output -->|"TrainingFeedback"| Train
    Output -->|"TestingEvaluation"| Test
    Output -->|"MetricCalculation"| Metrics
    Metrics -->|"Utilization"| Util
    Output -->|"VisualizedOutput"| Heatmap

    %% Click Events
    click Input "https://github.com/debeshjha/mdnet/tree/main/Img"
    click Encoder "https://github.com/debeshjha/mdnet/blob/main/mit.py"
    click FS "https://github.com/debeshjha/mdnet/blob/main/model.py"
    click D1 "https://github.com/debeshjha/mdnet/blob/main/model.py"
    click D2 "https://github.com/debeshjha/mdnet/blob/main/cbam.py"
    click Train "https://github.com/debeshjha/mdnet/blob/main/train.py"
    click Test "https://github.com/debeshjha/mdnet/blob/main/test.py"
    click Metrics "https://github.com/debeshjha/mdnet/blob/main/metrics.py"
    click Util "https://github.com/debeshjha/mdnet/blob/main/utils.py"
    click Heatmap "https://github.com/debeshjha/mdnet/blob/main/heatmap.py"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef utils fill:#90EE90,stroke:#000,stroke-width:2px;
```
