# alphaalimamy/famafuse architecture

> Architecture diagram of the GitHub repository alphaalimamy/famafuse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alphaalimamy/famafuse
- Repository: https://github.com/alphaalimamy/famafuse

## Overview

FAMAFuse is a PyTorch research implementation for multimodal medical-image fusion, specifically SPECT–MRI and PET–MRI. Its main workflow pairs modality images, trains a fusion network, saves weights, then evaluates the network to produce fused images; PET/SPECT evaluation restores the anatomical image’s color channels. The model combines inter-modal feature fusion, multiscale attention and spatial attention, while training uses similarity and mutual-information losses. The README identifies the paper but documents few operational details; this map follows the sampled Python source and omits uncertain wiring.

Main entry points: [`train.py`](https://github.com/alphaalimamy/famafuse/blob/master/train.py) (Training loop), [`model.py`](https://github.com/alphaalimamy/famafuse/blob/master/model.py) (FAMAFuse model), [`evaluate.py`](https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py) (Evaluation runner), [`plots_main.py`](https://github.com/alphaalimamy/famafuse/blob/master/plots_main.py) (Image comparison plots)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Image data"]
  node_train_data["Training patches<br/>[dataset.py]"]
  node_test_data["Test images<br/>[dataset.py]"]
end

subgraph group_fusion["Fusion network"]
  node_famafuse["FAMAFuse model<br/>[model.py]"]
  node_imff["Inter-modal fusion<br/>[model.py]"]
  node_mgaim["Multiscale attention<br/>[model.py]"]
  node_sarm["Spatial attention<br/>[model.py]"]
  node_fused_tensor["Fused image tensor<br/>[model.py]"]
end

subgraph group_train["Training"]
  node_train_loop["Training loop<br/>[train.py]"]
  node_fusion_losses["Fusion losses<br/>[losses.py]"]
  node_optimizer["Adam optimizer<br/>[train.py]"]
  node_checkpoint["Saved model weights<br/>[train.py]"]
end

subgraph group_infer["Evaluation and results"]
  node_evaluation["Evaluation runner<br/>[evaluate.py]"]
  node_restoration["Color restoration<br/>[evaluate.py]"]
  node_image_output["Fused image files<br/>[evaluate.py]"]
  node_comparison["Image comparison plots<br/>[plots_main.py]"]
  node_comparison_output["Comparison figures<br/>[plots_main.py]"]
end

node_researcher(("Researcher"))
node_paired_images["Paired modality images"]

node_researcher -->|"starts training"| node_train_loop
node_researcher -->|"runs evaluation"| node_evaluation
node_paired_images -->|"reads pairs"| node_train_data
node_paired_images -->|"reads pairs"| node_test_data
node_train_loop -->|"loads batches"| node_train_data
node_train_loop -->|"calls model"| node_famafuse
node_famafuse -->|"calls"| node_imff
node_famafuse -->|"calls"| node_mgaim
node_famafuse -->|"calls"| node_sarm
node_famafuse -->|"returns"| node_fused_tensor
node_train_loop -->|"computes loss"| node_fusion_losses
node_train_loop -->|"updates weights"| node_optimizer
node_train_loop -->|"saves best weights"| node_checkpoint
node_evaluation -->|"loads batches"| node_test_data
node_evaluation -.->|"loads weights"| node_checkpoint
node_evaluation -->|"calls model"| node_famafuse
node_evaluation -->|"restores channels"| node_restoration
node_restoration -->|"writes images"| node_image_output
node_image_output -->|"reads images"| node_comparison
node_comparison -->|"saves figures"| node_comparison_output

click node_train_data "https://github.com/alphaalimamy/famafuse/blob/master/dataset.py"
click node_test_data "https://github.com/alphaalimamy/famafuse/blob/master/dataset.py"
click node_famafuse "https://github.com/alphaalimamy/famafuse/blob/master/model.py"
click node_imff "https://github.com/alphaalimamy/famafuse/blob/master/model.py"
click node_mgaim "https://github.com/alphaalimamy/famafuse/blob/master/model.py"
click node_sarm "https://github.com/alphaalimamy/famafuse/blob/master/model.py"
click node_fused_tensor "https://github.com/alphaalimamy/famafuse/blob/master/model.py"
click node_train_loop "https://github.com/alphaalimamy/famafuse/blob/master/train.py"
click node_fusion_losses "https://github.com/alphaalimamy/famafuse/blob/master/losses.py"
click node_optimizer "https://github.com/alphaalimamy/famafuse/blob/master/train.py"
click node_checkpoint "https://github.com/alphaalimamy/famafuse/blob/master/train.py"
click node_evaluation "https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py"
click node_restoration "https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py"
click node_image_output "https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py"
click node_comparison "https://github.com/alphaalimamy/famafuse/blob/master/plots_main.py"
click node_comparison_output "https://github.com/alphaalimamy/famafuse/blob/master/plots_main.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_train_data,node_test_data toneBlue
class node_famafuse,node_imff,node_mgaim,node_sarm,node_fused_tensor toneAmber
class node_train_loop,node_fusion_losses,node_optimizer,node_checkpoint toneMint
class node_evaluation,node_restoration,node_image_output,node_comparison,node_comparison_output toneRose
class node_researcher,node_paired_images toneIndigo
```

## Components

### Image data

- [Training patches](https://github.com/alphaalimamy/famafuse/blob/master/dataset.py): `dataset.py`
- [Test images](https://github.com/alphaalimamy/famafuse/blob/master/dataset.py): `dataset.py`

### Fusion network

- [FAMAFuse model](https://github.com/alphaalimamy/famafuse/blob/master/model.py): `model.py`
- [Inter-modal fusion](https://github.com/alphaalimamy/famafuse/blob/master/model.py): `model.py`
- [Multiscale attention](https://github.com/alphaalimamy/famafuse/blob/master/model.py): `model.py`
- [Spatial attention](https://github.com/alphaalimamy/famafuse/blob/master/model.py): `model.py`
- [Fused image tensor](https://github.com/alphaalimamy/famafuse/blob/master/model.py): `model.py`

### Training

- [Training loop](https://github.com/alphaalimamy/famafuse/blob/master/train.py): `train.py`
- [Fusion losses](https://github.com/alphaalimamy/famafuse/blob/master/losses.py): `losses.py`
- [Adam optimizer](https://github.com/alphaalimamy/famafuse/blob/master/train.py): `train.py`
- [Saved model weights](https://github.com/alphaalimamy/famafuse/blob/master/train.py): `train.py`

### Evaluation and results

- [Evaluation runner](https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py): `evaluate.py`
- [Color restoration](https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py): `evaluate.py`
- [Fused image files](https://github.com/alphaalimamy/famafuse/blob/master/evaluate.py): `evaluate.py`
- [Image comparison plots](https://github.com/alphaalimamy/famafuse/blob/master/plots_main.py): `plots_main.py`
- [Comparison figures](https://github.com/alphaalimamy/famafuse/blob/master/plots_main.py): `plots_main.py`

### Other components

- **Researcher**
- **Paired modality images**

## Connections

- Researcher → Training loop: starts training
- Researcher → Evaluation runner: runs evaluation
- Paired modality images → Training patches: reads pairs
- Paired modality images → Test images: reads pairs
- Training loop → Training patches: loads batches
- Training loop → FAMAFuse model: calls model
- FAMAFuse model → Inter-modal fusion: calls
- FAMAFuse model → Multiscale attention: calls
- FAMAFuse model → Spatial attention: calls
- FAMAFuse model → Fused image tensor: returns
- Training loop → Fusion losses: computes loss
- Training loop → Adam optimizer: updates weights
- Training loop → Saved model weights: saves best weights
- Evaluation runner → Test images: loads batches
- Evaluation runner → Saved model weights: loads weights
- Evaluation runner → FAMAFuse model: calls model
- Evaluation runner → Color restoration: restores channels
- Color restoration → Fused image files: writes images
- Fused image files → Image comparison plots: reads images
- Image comparison plots → Comparison figures: saves figures
