# zhangxd0530/ms-dsa-net architecture

> Architecture diagram of the GitHub repository zhangxd0530/ms-dsa-net, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhangxd0530/ms-dsa-net
- Repository: https://github.com/zhangxd0530/ms-dsa-net

## Overview

MS-DSA-NET is a 3D focal cortical dysplasia lesion-segmentation application for paired T1 and FLAIR MRI. Its documented user workflow prepares subject images, registers them to the MNI template, runs the pretrained segmentation model, and saves a lesion map for viewing. The graph preserves the preprocessing, image transforms, network, and lesion post-processing stages, plus evaluation utilities. The inference entry point is described in the README but its source was not sampled, so workflow links rely on that documentation; internal inference details are omitted.

Main entry points: [`seg_fcd_test.py`](https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py) (Test inference), [`networks2/ms_dsa_net.py`](https://github.com/zhangxd0530/ms-dsa-net/blob/main/networks2/ms_dsa_net.py) (MS-DSA-NET), [`preprocess_data.py`](https://github.com/zhangxd0530/ms-dsa-net/blob/main/preprocess_data.py) (FSL registration), [`inputs/raw`](https://github.com/zhangxd0530/ms-dsa-net/tree/main/inputs/raw) (T1 + FLAIR MRI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preparation["Image preparation"]
  node_raw_mri["T1 + FLAIR MRI"]
  node_registration["FSL registration<br/>[preprocess_data.py]"]
  node_mni_template["MNI template"]
  node_registered_mri["Registered MRI<br/>[preprocess_data.py]"]
  node_input_transforms["Input transforms<br/>[get_transforms.py]"]
end

subgraph group_inference["Segmentation"]
  node_test_runner["Test inference<br/>[seg_fcd_test.py]"]
  node_model_factory["Model factory<br/>[get_model.py]"]
  node_ms_dsa_net["MS-DSA-NET<br/>[ms_dsa_net.py]"]
  node_cnn_blocks["CNN and attention blocks<br/>[conv_blocks.py]"]
  node_output_transforms["Prediction transforms<br/>[get_transforms.py]"]
  node_lesion_map["Lesion map<br/>[seg_fcd_test.py]"]
  node_pretrained_weights["Pretrained weights"]
  node_saved_results["Saved results<br/>[seg_fcd_test.py]"]
end

subgraph group_support["Model support"]
  node_lesion_cleanup["Lesion post-processing<br/>[utils_common.py]"]
  node_evaluation["Segmentation evaluation<br/>[utils_common.py]"]
  node_losses["Segmentation losses<br/>[get_loss.py]"]
  node_training_transforms["Training transforms<br/>[get_transforms.py]"]
  node_gridmask["GridMask augmentation<br/>[gridmask.py]"]
  node_schedulers["Learning-rate schedules<br/>[lr_scheduler.py]"]
end

node_user(("Research user"))
node_mitk(("MITK viewer"))

node_user -->|"provides"| node_raw_mri
node_raw_mri -->|"registers"| node_registration
node_mni_template -->|"guides registration"| node_registration
node_registration -->|"writes"| node_registered_mri
node_registered_mri -->|"loads"| node_test_runner
node_test_runner -.->|"prepares images"| node_input_transforms
node_test_runner -.->|"selects model"| node_model_factory
node_model_factory -->|"constructs"| node_ms_dsa_net
node_ms_dsa_net -->|"uses blocks"| node_cnn_blocks
node_pretrained_weights -.->|"loads weights"| node_test_runner
node_test_runner -->|"predicts lesions"| node_ms_dsa_net
node_test_runner -.->|"post-processes prediction"| node_output_transforms
node_test_runner -.->|"cleans prediction"| node_lesion_cleanup
node_test_runner -->|"produces"| node_lesion_map
node_lesion_map -->|"saves"| node_saved_results
node_saved_results -->|"viewed in"| node_mitk
node_evaluation -.->|"evaluates"| node_lesion_map
node_losses -.->|"scores training output"| node_ms_dsa_net
node_training_transforms -.->|"may augment with"| node_gridmask
node_schedulers -.->|"schedules optimization"| node_losses

click node_raw_mri "https://github.com/zhangxd0530/ms-dsa-net/tree/main/inputs/raw"
click node_registration "https://github.com/zhangxd0530/ms-dsa-net/blob/main/preprocess_data.py"
click node_mni_template "https://github.com/zhangxd0530/ms-dsa-net/blob/main/inputs/MNI152_T1_1mm.nii.gz"
click node_registered_mri "https://github.com/zhangxd0530/ms-dsa-net/blob/main/preprocess_data.py"
click node_input_transforms "https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_transforms.py"
click node_test_runner "https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py"
click node_model_factory "https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_model.py"
click node_ms_dsa_net "https://github.com/zhangxd0530/ms-dsa-net/blob/main/networks2/ms_dsa_net.py"
click node_cnn_blocks "https://github.com/zhangxd0530/ms-dsa-net/blob/main/networks2/conv_blocks.py"
click node_output_transforms "https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_transforms.py"
click node_lesion_cleanup "https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/utils_common.py"
click node_lesion_map "https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py"
click node_evaluation "https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/utils_common.py"
click node_losses "https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_loss.py"
click node_training_transforms "https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_transforms.py"
click node_gridmask "https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/gridmask.py"
click node_schedulers "https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/lr_scheduler.py"
click node_saved_results "https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_raw_mri,node_registration,node_mni_template,node_registered_mri,node_input_transforms,node_user,node_mitk toneBlue
class node_test_runner,node_model_factory,node_ms_dsa_net,node_cnn_blocks,node_output_transforms,node_lesion_map,node_pretrained_weights,node_saved_results toneAmber
class node_lesion_cleanup,node_evaluation,node_losses,node_training_transforms,node_gridmask,node_schedulers toneMint
```

## Components

### Image preparation

- [T1 + FLAIR MRI](https://github.com/zhangxd0530/ms-dsa-net/tree/main/inputs/raw): `inputs/raw`
- [FSL registration](https://github.com/zhangxd0530/ms-dsa-net/blob/main/preprocess_data.py): `preprocess_data.py`
- [MNI template](https://github.com/zhangxd0530/ms-dsa-net/blob/main/inputs/MNI152_T1_1mm.nii.gz): `inputs/MNI152_T1_1mm.nii.gz`
- [Registered MRI](https://github.com/zhangxd0530/ms-dsa-net/blob/main/preprocess_data.py): `preprocess_data.py`
- [Input transforms](https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_transforms.py): `get_transforms.py`

### Segmentation

- [Test inference](https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py): `seg_fcd_test.py`
- [Model factory](https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_model.py): `get_model.py`
- [MS-DSA-NET](https://github.com/zhangxd0530/ms-dsa-net/blob/main/networks2/ms_dsa_net.py): `networks2/ms_dsa_net.py`
- [CNN and attention blocks](https://github.com/zhangxd0530/ms-dsa-net/blob/main/networks2/conv_blocks.py): `networks2/conv_blocks.py`
- [Prediction transforms](https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_transforms.py): `get_transforms.py`
- [Lesion map](https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py): `seg_fcd_test.py`
- **Pretrained weights**
- [Saved results](https://github.com/zhangxd0530/ms-dsa-net/blob/main/seg_fcd_test.py): `seg_fcd_test.py`

### Model support

- [Lesion post-processing](https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/utils_common.py): `utils2/utils_common.py`
- [Segmentation evaluation](https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/utils_common.py): `utils2/utils_common.py`
- [Segmentation losses](https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_loss.py): `get_loss.py`
- [Training transforms](https://github.com/zhangxd0530/ms-dsa-net/blob/main/get_transforms.py): `get_transforms.py`
- [GridMask augmentation](https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/gridmask.py): `utils2/gridmask.py`
- [Learning-rate schedules](https://github.com/zhangxd0530/ms-dsa-net/blob/main/utils2/lr_scheduler.py): `utils2/lr_scheduler.py`

### Other components

- **Research user**
- **MITK viewer**

## Connections

- Research user → T1 + FLAIR MRI: provides (evidence: `README.md`)
- T1 + FLAIR MRI → FSL registration: registers (evidence: `README.md`)
- MNI template → FSL registration: guides registration (evidence: `preprocess_data.py`)
- FSL registration → Registered MRI: writes (evidence: `preprocess_data.py`)
- Registered MRI → Test inference: loads (evidence: `README.md`)
- Test inference → Input transforms: prepares images
- Test inference → Model factory: selects model
- Model factory → MS-DSA-NET: constructs (evidence: `get_model.py`)
- MS-DSA-NET → CNN and attention blocks: uses blocks (evidence: `networks2/ms_dsa_net.py`)
- Pretrained weights → Test inference: loads weights (evidence: `README.md`)
- Test inference → MS-DSA-NET: predicts lesions (evidence: `README.md`)
- Test inference → Prediction transforms: post-processes prediction
- Test inference → Lesion post-processing: cleans prediction
- Test inference → Lesion map: produces (evidence: `README.md`)
- Lesion map → Saved results: saves (evidence: `README.md`)
- Saved results → MITK viewer: viewed in (evidence: `README.md`)
- Segmentation evaluation → Lesion map: evaluates
- Segmentation losses → MS-DSA-NET: scores training output
- Training transforms → GridMask augmentation: may augment with
- Learning-rate schedules → Segmentation losses: schedules optimization
