• Stars
    star
    2,136
  • Rank 20,799 (Top 0.5 %)
  • Language
    Jupyter Notebook
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated 26 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Segment Anything in Medical Images

MedSAM

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

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
python MedSAM_Inference.py # segment the demo image

Segment other images with the following flags

-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 MedSAM_Inference.ipynb.

  1. GUI

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

python gui.py

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

seg_demo

seg_pathology.mp4

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

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 1024x2014
  • 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.

sbatch train_multi_gpus.sh

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

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

Training on one GPU

python train_one_gpu.py

If you only want to train the mask decoder, please check the tutorial on the 0.1 branch.

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 and Wang, Bo},
  journal={arXiv preprint arXiv:2304.12306},
  year={2023}
}

More Repositories

1

scGPT

Jupyter Notebook
815
star
2

U-Mamba

U-Mamba: Enhancing Long-range Dependency for Biomedical Image Segmentation
Python
445
star
3

Graph-Mamba

Graph-Mamba: Towards Long-Range Graph Sequence Modelling with Selective State Spaces
Python
134
star
4

joint-ner-and-re

This repository contains the corpora and supplementary data, along with instructions for recreating the experiments, for our paper: "End-to-end Named Entity Recognition and Relation Extraction using Pre-trained Language Models".
Jupyter Notebook
90
star
5

MedSAMSlicer

3D Slicer Plugin for Segment anything in medical images
Python
74
star
6

BIONIC

Biological Network Integration using Convolutions
Python
55
star
7

clinical-camel

Python
47
star
8

BLEEP

Spatially Resolved Gene Expression Prediction from H&E Histology Images via Bi-modal Contrastive Learning
Python
40
star
9

DeepVelo

Python
34
star
10

MEDIQA-Chat-2023

A repository for organizing our submission to the MEDIQA-Chat Tasks @ ACL-ClinicalNLP 2023
Python
19
star
11

AGILE

AGILE Platform: A Deep Learning-Powered Approach to Accelerate LNP Development for mRNA Delivery
Python
18
star
12

OCAT

Python
17
star
13

scFormer

Python
16
star
14

Transformer-GCN-QA

A multi-hop Q/A architecture based on transformers and GCNs.
Python
15
star
15

DPM-MedImgEnhance

Pre-trained Diffusion Models for Plug-and-Play Medical Image Enhancement
Python
14
star
16

MAESTER

Masked Autoencoder Guided Segmentation at Pixel Resolution
Python
11
star
17

CONCERTO

Carcinogenicity prediction with graph neural networks
Jupyter Notebook
10
star
18

LabChat

Jupyter Notebook
9
star
19

NanoMASK

mouse pet-ct image segmentation
Python
7
star
20

simATAC

A single-cell ATAC-seq simulation framework (R package)
R
5
star
21

Transplant_Time_Series

HTML
5
star
22

CongFu

CongFu: Conditional Graph Fusion for Drug Synergy Prediction
Python
5
star
23

DES

Single-Shot Object Detection with Enriched Semantics
C++
4
star
24

SIMLR_PY

Python version of SIMLR
Python
3
star
25

IntegrAO

Integrate Any Omics: Towards genome-wide data integration for patient stratification
Jupyter Notebook
3
star
26

SIMLR

Single-cell Interpretation via Multi-kernel LeaRning
R
2
star
27

unicell

Universal cellular segmentation models
Python
2
star
28

gcn-drug-repurposing

Python
2
star
29

shape-attentive-unet

Code for our paper SAUNet: Shape Attentive U-Net for Interpretable Medical Image Segmentation. https://arxiv.org/pdf/2001.07645.pdf
Python
1
star
30

ViST-Echo

PD's thesis work towards a Video Swin Transformer for echocardiographic data.
Python
1
star