๐ฅ SAMed-2:Selective Memory Enhanced Medical SAM
October 27, 2025 ยท View on GitHub
๐ฅ SAMed-2:
Selective Memory Enhanced Medical SAM
Medical Image Segmentation with Memory-Enhanced SAM
The Official Repository of SAMed-2 & Medical SAM Benchmark
Installation โข Models โข Quick Start โข Citation
๐ Highlights
| ๐ง Memory-Enhanced SOTA Best performance on medical benchmarks |
๐ง Unified Framework Fair comparison of all Medical SAM variants |
๐ Abstract
SAMed-2 is a new foundation model for medical image segmentation built upon the SAM-2 architecture. Specifically, we introduce a temporal adapter into the image encoder to capture image correlations and a confidence-driven memory mechanism to store high-certainty features for later retrieval. This memory-based strategy counters the pervasive noise in large-scale medical datasets and mitigates catastrophic forgetting when encountering new tasks or modalities.
๐ฐ News
[06/2025] ๐ SAMed-2 is accepted by MICCAI 2025!
[06/2025] ๐ Initial release of SAMed-2!
๐ Code License
This project is released under the Apache 2.0 license.
๐ Getting Started
1. Installation
Linux Environment
Clone this repository and navigate to the folder:
git clone https://github.com/ZhilingYan/Medical-SAM-Bench.git
cd Medical-SAM-Bench
2. Install Package
# Create a new conda environment
conda create -n samed2 python=3.10 -y
conda activate samed2
# Install PyTorch (adjust cuda version as needed)
pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cu118
# Install other requirements
pip install -r requirements.txt
3. Model Zoo
| Model | Architecture | Medical Fine-tuned | Performance | Download |
|---|---|---|---|---|
| SAMed-2 โญ | SAM2-Hiera-S | โ | Best | ๐ฅ Download |
| MedSAM2 | SAM2-Hiera-T | โ | Good | ๐ฅ Download |
| MedSAM | SAM-ViT-B | โ | Good | ๐ฅ Download |
| SAM2 | SAM2-Hiera-S | โ | Baseline | ๐ฅ Download |
| SAM | SAM-ViT-B | โ | Baseline | ๐ฅ Download |
๐ Place downloaded weights in
./checkpoints/
๐พ Memory Bank (Required for SAMed-2)
Download the pre-trained memory bank: memory_bank_list_640.pkl
Place it in the root directory of this repository.
4. Quick Start
๐ Simple Python API
from predict import MedicalSegmenter
# Initialize
segmenter = MedicalSegmenter(
model_type='samed2',
checkpoint_path='checkpoints/latest_epoch_0217.pth'
)
# Segment
result = segmenter.predict(
'medical_image.png',
box=[100, 100, 900, 900]
)
# Visualize
segmenter.visualize(
'medical_image.png',
result['mask'],
'result.jpg'
)
๐ Benchmark Medical SAM Models
# ๐ SAMed-2 (Ours)
python main.py -net samed2 -sam_ckpt checkpoints/latest_epoch_0217.pth -sam_config sam2_hiera_s
# ๐ฌ MedSAM2
python main.py -net medsam2 -sam_ckpt checkpoints/MedSAM2_pretrain.pth -sam_config sam2_hiera_t_original
# ๐ฅ MedSAM
python main.py -net medsam -sam_ckpt checkpoints/medsam_vit_b.pth
# ๐ฏ SAM2
python main.py -net sam2 -sam_ckpt checkpoints/sam2_hiera_small.pt -sam_config sam2_hiera_s_original
# ๐ท SAM
python main.py -net sam -sam_ckpt checkpoints/sam_vit_b_01ec64.pth
๐ก Common:
-exp_name ${DATASET} -image_size 1024 -data_path /path/to/data -val_file_dir /path/to/test.txt
5. Evaluation
๐ฆ Download Test Datasets
| Dataset | Modality | Size | Download |
|---|---|---|---|
| Optic Cup | Fundus | ~100MB | ๐ฅ Download |
| Brain Tumor | MRI | ~100MB | ๐ฅ Download |
Prepare Your Own Dataset
For custom datasets, organize your data as follows:
your_dataset/
โโโ image/
โ โโโ case_idx_slice_001.png
โ โโโ case_idx_slice_002.png
โ โโโ ...
โโโ mask/
โ โโโ case_idx_slice_001.png
โ โโโ case_idx_slice_002.png
โ โโโ ...
โโโ test.txt # List of test image names
Run Evaluation
# Full evaluation on the dataset
bash run.sh
Parameters Explanation:
-net: Model type (samed2,medsam2,sam2,medsam,sam)-exp_name: Dataset name for logging-sam_ckpt: Path to model checkpoint-sam_config: Configuration file-image_size: Input image size (default: 1024)-out_size: Output size (default: 1024)-b: Batch size-data_path: Root path to datasets-train_file_dir: Path to training file list-val_file_dir: Path to validation file list-memory_bank_size: Memory bank size for SAMed2 (default: 640)-lr: Learning rate (default: 1e-4)-epoch: Number of epochs (default: 100)
๐ Performance Comparison
| Dataset | SAM | MedSAM | SAM2 | MedSAM2 | SAMed-2 |
|---|---|---|---|---|---|
| OpticCup | 0.61 | 0.86 | 0.62 | 0.40 | 0.90 ๐ |
| BrainTumor | 0.56 | 0.60 | 0.44 | 0.58 | 0.67 ๐ |
Dice scores on test sets. Higher is better.
๐ Citation & Contributors
If you find SAMed-2 useful in your research, please consider citing:
@article{yan2025samed,
title={SAMed-2: Selective Memory Enhanced Medical Segment Anything Model},
author={Yan, Zhiling and Song, Sifan and Song, Dingjie and Li, Yiwei and Zhou, Rong and Sun, Weixiang and Chen, Zhennong and Kim, Sekeun and Ren, Hui and Liu, Tianming and others},
journal={arXiv preprint arXiv:2507.03698},
year={2025}
}
Contributors:
Zhiling Yanยน, Sifan Songยฒ, Dingjie Songยน, Yiwei Liยณ, Rong Zhouยน, Weixiang Sunโด, Zhennong Chenยฒ, Sekeun Kimยฒ, Hui Renยฒ, Tianming Liuยณ, Quanzheng Liยฒ, Xiang Liยฒ, Lifang Heยน, Lichao Sunยน*
ยนLehigh University
ยฒMassachusetts General Hospital and Harvard Medical School
ยณUniversity of Georgia, Athens
โดUniversity of Notre Dame
๐ Acknowledgements
We gratefully acknowledge: