https://github.com/bowang-lab/medsam2
MedSAM2: Segment Anything in 3D Medical Images and Videos
Science Score: 49.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 2 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org, sciencedirect.com -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.6%) to scientific vocabulary
Repository
MedSAM2: Segment Anything in 3D Medical Images and Videos
Basic Info
- Host: GitHub
- Owner: bowang-lab
- License: apache-2.0
- Language: Python
- Default Branch: main
- Homepage: https://medsam2.github.io/
- Size: 18.2 MB
Statistics
- Stars: 236
- Watchers: 5
- Forks: 54
- Open Issues: 2
- Releases: 0
Metadata Files
README.md
MedSAM2
Welcome to join our mailing list to get updates. We’re also actively looking to collaborate on annotating new large-scale 3D datasets. If you have unlabeled medical images or videos and want to share them with the community, let’s connect!
Updates
- 20250705: Release Efficient MedSAM2 baseline for FLARE 2025 Pan-cancer segmentation challenge RECIST-to-3D
- 20250423: Release lung lesion segmentation dataset LUNA25-MedSAM2 for LUNA25
Installation
- Create a virtual environment:
conda create -n medsam2 python=3.12 -yandconda activate medsam2 - Install PyTorch:
pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cu124(Linux CUDA 12.4) - Download code
git clone https://github.com/bowang-lab/MedSAM2.git && cd MedSAM2and runpip install -e ".[dev]" - Download checkpoints:
bash download.sh - Optional: Please install the following dependencies for gradio
bash
sudo apt-get update
sudo apt-get install ffmpeg
pip install gradio==3.38.0
pip install numpy==1.26.3
pip install ffmpeg-python
pip install moviepy
Download annotated datasets
Note: Please also cite the raw DeepLesion, LLD-MMRI and RVENET papers when using these datasets.
Inference
3D medical image segmentation
bash
python medsam2_infer_3D_CT.py -i CT_DeepLesion/images -o CT_DeepLesion/segmentation
Medical video segmentation
bash
python medsam2_infer_video.py -i input_video_path -m input_mask_path -o output_video_path
Gradio demo
bash
python app.py
Training MedSAM2
Use FLARE25 pan-cancer CT dataset as an example.
- Download sam2.1hieratiny.pt to checkpoints
- Add dataset information in sam2/configs/sam2.1_hiera_tiny512_FLARE_RECIST.yaml: data -> train -> datasets
- Set train_video_batch_size based on the GPU memory
bash
sh single_node_train_medsam2.sh
- multi-node training
bash
sbatch multi_node_train.sh
- inference with RECIST marker (simulate a box prompt on middle slice)
bash
python medsam2_infer_CT_lesion_npz_recist.py
Training Efficient MedSAM2
- Train Efficient MedSAM2 on FLARE25 pan-cancer CT dataset for CPU-based inference
bash
sh single_node_train_eff_medsam2_FLARE25.sh
- Inference with RECIST marker on the FLARE25 pan-cancer validation dataset.
python
npz = np.load('path to/CT_Lesion_FLARE23Ts_0057.npz', allow_pickle=True)
print(npz.keys())
imgs = npz['imgs'] # (D, W, H), [0, 255]
recist = npz['recist'] # (D, W, H), binary RECIST marker on tumor middle slice {0, 1}
gts = npz['gts'] # (D, W, H), 3D tumor ground truth mask. It will be not available in the testing set
simulate a box prompt on middle slice
bash
python eff_medsam2_infer_CT_lesion_npz_recist.py
Acknowledgements
- We highly appreciate all the challenge organizers and dataset owners for providing the public datasets to the community.
- We thank Meta AI for making the source code of SAM2 and EfficientTAM publicly available. Please also cite these papers when using MedSAM2.
Bibtex
bash
@article{MedSAM2,
title={MedSAM2: Segment Anything in 3D Medical Images and Videos},
author={Ma, Jun and Yang, Zongxin and Kim, Sumin and Chen, Bihui and Baharoon, Mohammed and Fallahpour, Adibvafa and Asakereh, Reza and Lyu, Hongwei and Wang, Bo},
journal={arXiv preprint arXiv:2504.03600},
year={2025}
}
Please also cite SAM2
@inproceedings{SAM2,
title={{SAM} 2: Segment Anything in Images and Videos},
author={Nikhila Ravi and Valentin Gabeur and Yuan-Ting Hu and Ronghang Hu and Chaitanya Ryali and Tengyu Ma and Haitham Khedr and Roman R{\"a}dle and Chloe Rolland and Laura Gustafson and Eric Mintun and Junting Pan and Kalyan Vasudev Alwala and Nicolas Carion and Chao-Yuan Wu and Ross Girshick and Piotr Dollar and Christoph Feichtenhofer},
booktitle={International Conference on Learning Representations},
year={2025}
}
and EfficientTAM
@article{xiong2024efficienttam,
title={Efficient Track Anything},
author={Yunyang Xiong, Chong Zhou, Xiaoyu Xiang, Lemeng Wu, Chenchen Zhu, Zechun Liu, Saksham Suri, Balakrishnan Varadarajan, Ramya Akula, Forrest Iandola, Raghuraman Krishnamoorthi, Bilge Soran, Vikas Chandra},
journal={preprint arXiv:2411.18933},
year={2024}
}
Owner
- Name: WangLab @ U of T
- Login: bowang-lab
- Kind: organization
- Location: 190 Elizabeth St, Toronto, ON M5G 2C4 Canada
- Website: https://wanglab.ml
- Repositories: 11
- Profile: https://github.com/bowang-lab
BoWang's Lab at University of Toronto
GitHub Events
Total
- Issues event: 39
- Watch event: 240
- Issue comment event: 40
- Member event: 2
- Push event: 18
- Pull request review event: 2
- Pull request event: 4
- Fork event: 47
- Create event: 2
Last Year
- Issues event: 39
- Watch event: 240
- Issue comment event: 40
- Member event: 2
- Push event: 18
- Pull request review event: 2
- Pull request event: 4
- Fork event: 47
- Create event: 2
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| junma11 | 1****4@q****m | 11 |
| Adibvafa Fallahpour | 9****a | 4 |
| ww | w****n@o****m | 1 |
| Mukkesh Ganesh | m****e@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 15
- Total pull requests: 3
- Average time to close issues: 4 days
- Average time to close pull requests: about 4 hours
- Total issue authors: 14
- Total pull request authors: 3
- Average comments per issue: 1.87
- Average comments per pull request: 0.67
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 15
- Pull requests: 3
- Average time to close issues: 4 days
- Average time to close pull requests: about 4 hours
- Issue authors: 14
- Pull request authors: 3
- Average comments per issue: 1.87
- Average comments per pull request: 0.67
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- KhlYanis (2)
- NirmanBharti (1)
- CarolineMagg (1)
- ShadowTwin41 (1)
- zez1998216 (1)
- NimaDL (1)
- xyimaging (1)
- idilsevis (1)
- wjh-lilly (1)
- kimsekeun (1)
- ankanpy (1)
- bbuok-neu (1)
- kushalX13 (1)
- void-mckenzie (1)
- fedorov (1)
Pull Request Authors
- void-mckenzie (2)
- whitewatercn (2)
- jagh (2)