https://github.com/bowang-lab/medsam

Segment Anything in Medical Images

https://github.com/bowang-lab/medsam

Science Score: 46.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
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    2 of 11 committers (18.2%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Segment Anything in Medical Images

Basic Info
Statistics
  • Stars: 3,527
  • Watchers: 27
  • Forks: 493
  • Open Issues: 5
  • Releases: 1
Created almost 3 years ago · Last pushed 10 months ago
Metadata Files
Readme License

README.md

MedSAM

This is the official repository for MedSAM: Segment Anything in Medical Images.

Welcome to join our mailing list to get updates.

News

Installation

  1. Create a virtual environment conda create -n medsam python=3.10 -y and activate it conda activate medsam
  2. Install Pytorch 2.0
  3. git clone https://github.com/bowang-lab/MedSAM
  4. Enter the MedSAM folder cd MedSAM and run pip install -e .

Get Started

Download the model checkpoint and place it at e.g., work_dir/MedSAM/medsam_vit_b

We provide three ways to quickly test the model on your images

  1. Command line

bash python MedSAM_Inference.py # segment the demo image

Segment other images with the following flags bash -i input_img -o output path --box bounding box of the segmentation target

  1. Jupyter-notebook

We provide a step-by-step tutorial on CoLab

You can also run it locally with tutorial_quickstart.ipynb.

  1. GUI

Install PyQt5 with pip: pip install PyQt5 or conda: conda install -c anaconda pyqt

bash python gui.py

Load the image to the GUI and specify segmentation targets by drawing bounding boxes.

https://github.com/bowang-lab/MedSAM/assets/19947331/a8d94b4d-0221-4d09-a43a-1251842487ee

Model Training

Data preprocessing

Download SAM checkpoint and place it at work_dir/SAM/sam_vit_b_01ec64.pth .

Download the demo dataset and unzip it to data/FLARE22Train/.

This dataset contains 50 abdomen CT scans and each scan contains an annotation mask with 13 organs. The names of the organ label are available at MICCAI FLARE2022.

Run pre-processing

Install cc3d: pip install connected-components-3d

bash python pre_CT_MR.py

  • split dataset: 80% for training and 20% for testing
  • adjust CT scans to soft tissue window level (40) and width (400)
  • max-min normalization
  • resample image size to 1024x1024
  • save the pre-processed images and labels as npy files

Training on multiple GPUs (Recommend)

The model was trained on five A100 nodes and each node has four GPUs (80G) (20 A100 GPUs in total). Please use the slurm script to start the training process.

bash sbatch train_multi_gpus.sh

When the training process is done, please convert the checkpoint to SAM's format for convenient inference.

bash python utils/ckpt_convert.py # Please set the corresponding checkpoint path first

Training on one GPU

bash python train_one_gpu.py

Acknowledgements

  • We highly appreciate all the challenge organizers and dataset owners for providing the public dataset to the community.
  • We thank Meta AI for making the source code of segment anything publicly available.
  • We also thank Alexandre Bonnet for sharing this great blog

Reference

@article{MedSAM, title={Segment Anything in Medical Images}, author={Ma, Jun and He, Yuting and Li, Feifei and Han, Lin and You, Chenyu and Wang, Bo}, journal={Nature Communications}, volume={15}, pages={654}, year={2024} }

Owner

  • Name: WangLab @ U of T
  • Login: bowang-lab
  • Kind: organization
  • Location: 190 Elizabeth St, Toronto, ON M5G 2C4 Canada

BoWang's Lab at University of Toronto

GitHub Events

Total
  • Issues event: 120
  • Watch event: 802
  • Issue comment event: 84
  • Push event: 5
  • Pull request review event: 1
  • Pull request event: 3
  • Fork event: 130
Last Year
  • Issues event: 120
  • Watch event: 802
  • Issue comment event: 84
  • Push event: 5
  • Pull request review event: 1
  • Pull request event: 3
  • Fork event: 130

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 122
  • Total Committers: 11
  • Avg Commits per committer: 11.091
  • Development Distribution Score (DDS): 0.311
Past Year
  • Commits: 11
  • Committers: 4
  • Avg Commits per committer: 2.75
  • Development Distribution Score (DDS): 0.273
Top Committers
Name Email Commits
Jun 1****4@q****m 84
Fraol Gelana f****a@g****m 17
Lin Han me@l****l 10
Pse1234 7****4 4
sarrabenyahia 9****a 1
ff98li f****i@m****a 1
Zehui Lin z****t@o****m 1
Kalina Slavkova k****v@u****u 1
Ajinkya Kulkarni k****a@g****m 1
ctrlaltf2 c****2@p****h 1
Khoa-NT t****4@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 254
  • Total pull requests: 20
  • Average time to close issues: 14 days
  • Average time to close pull requests: 21 days
  • Total issue authors: 215
  • Total pull request authors: 13
  • Average comments per issue: 1.92
  • Average comments per pull request: 0.25
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 82
  • Pull requests: 3
  • Average time to close issues: 20 days
  • Average time to close pull requests: about 3 hours
  • Issue authors: 74
  • Pull request authors: 2
  • Average comments per issue: 1.07
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mehrnia (5)
  • PANHAOC (3)
  • ariharasudhanm (3)
  • mlszy928 (3)
  • panboshui (3)
  • biyuefeng (2)
  • GewelsJI (2)
  • hnyll (2)
  • Youzhuqinghuan (2)
  • MyFirst905 (2)
  • 1687412531 (2)
  • Ulteraa (2)
  • Biopticon (2)
  • liubaoning111 (2)
  • xiawei20161308104 (2)
Pull Request Authors
  • linhandev (3)
  • GoobleNeat (3)
  • JoseAngelGarciaSanchez (3)
  • FrexG (3)
  • oikosohn (2)
  • Zehui-Lin (2)
  • kslav (2)
  • BBQtime (2)
  • ff98li (2)
  • junautogroup (1)
  • ctrlaltf2 (1)
  • chinmay5 (1)
  • sarrabenyahia (1)
  • hamzaMahdi (1)
  • ajinkya-kulkarni (1)
Top Labels
Issue Labels
enhancement (6) question (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads: unknown
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 2
proxy.golang.org: github.com/bowang-lab/MedSAM
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 7.0%
Last synced: 6 months ago
proxy.golang.org: github.com/bowang-lab/medsam
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 7.0%
Last synced: 6 months ago