Skip to content

bowang-lab/MedSAM2

Repository files navigation

MedSAM2

Segment Anything in 3D Medical Images and Videos

Paper Project Code HuggingFace Model
Dataset List CT_DeepLesion-MedSAM2 LLD-MMRI-MedSAM2 3D Slicer
Gradio App CT-Seg-Demo Video-Seg-Demo BibTeX

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!

Installation

  • Create a virtual environment: conda create -n medsam2 python=3.12 -y and conda activate medsam2
  • Install PyTorch: pip3 install torch torchvision (Linux CUDA 12.4)
  • Download code git clone https://github.com/bowang-lab/MedSAM2.git && cd MedSAM2 and run pip install -e ".[dev]"
  • Download checkpoints: sh download.sh
  • Optional: Please install the following dependencies for gradio
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 and LLD-MMRI dataset paper when using these datasets.

  • RVENET: Waiting for authors' approval to release the mask.

Inference

3D medical image segmentation

python medsam2_infer_3D_CT.py -i CT_DeepLesion/images -o CT_DeepLesion/segmentation

Medical video segmentation

python medsam2_infer_video.py -i input_video_path -m input_mask_path -o output_video_path 

Gradio demo

python app.py

Training

Specify dataset path in sam2/configs/sam2.1_hiera_tiny_finetune512.yaml

sbatch multi_node_train.sh

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 publicly available. Please also cite this paper when using MedSAM2.

Bibtex

@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

@article{ravi2024sam2,
  title={SAM 2: Segment Anything in Images and Videos},
  author={Ravi, Nikhila and Gabeur, Valentin and Hu, Yuan-Ting and Hu, Ronghang and Ryali, Chaitanya and Ma, Tengyu and Khedr, Haitham and R{\"a}dle, Roman and Rolland, Chloe and Gustafson, Laura and Mintun, Eric and Pan, Junting and Alwala, Kalyan Vasudev and Carion, Nicolas and Wu, Chao-Yuan and Girshick, Ross and Doll{\'a}r, Piotr and Feichtenhofer, Christoph},
  journal={arXiv preprint arXiv:2408.00714},
  url={https://arxiv.org/abs/2408.00714},
  year={2024}
}

About

MedSAM2: Segment Anything in 3D Medical Images and Videos

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published