https://github.com/cvhub520/sam-med2d
Official implementation of SAM-Med2D
Science Score: 10.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.2%) to scientific vocabulary
Repository
Official implementation of SAM-Med2D
Basic Info
- Host: GitHub
- Owner: CVHub520
- License: apache-2.0
- Language: Jupyter Notebook
- Default Branch: main
- Size: 26.6 MB
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
SAM-Med2D [Paper]
🌤️ Highlights
- 🏆 Collected and curated the largest medical image segmentation dataset (4.6M images and 19.7M masks) to date for training models.
- 🏆 The most comprehensive fine-tuning based on Segment Anything Model (SAM).
- 🏆 Comprehensive evaluation of SAM-Med2D on large-scale datasets.
🔥 Updates
- (2023.09.02) Test code release
- (2023.08.31) Pre-trained model release
- (2023.08.31) Paper release
- (2023.08.26) Online Demo release
👉 Dataset
SAM-Med2D is trained and tested on a dataset that includes 4.6M images and 19.7M masks. This dataset covers 10 medical data modalities, 4 anatomical structures + lesions, and 31 major human organs. To our knowledge, this is currently the largest and most diverse medical image segmentation dataset in terms of quantity and coverage of categories.

👉 Framework
The pipeline of SAM-Med2D. We freeze the image encoder and incorporate learnable adapter layers in each Transformer block to acquire domain-specific knowledge in the medical field. We fine-tune the prompt encoder using point, Bbox, and mask information, while updating the parameters of the mask decoder through interactive training.

👉 Results
| Model | Resolution | Bbox (%) | 1 pt (%) | 3 pts (%) | 5 pts (%) | FPS | Checkpoint |
|---|---|---|---|---|---|---|---|
| SAM | $256\times256$ | 61.63 | 18.94 | 28.28 | 37.47 | 51 | Offical |
| SAM | $1024\times1024$ | 74.49 | 36.88 | 42.00 | 47.57 | 8 | Offical |
| FT-SAM | $256\times256$ | 73.56 | 60.11 | 70.95 | 75.51 | 51 | FT-SAM |
| SAM-Med2D | $256\times256$ | 79.30 | 70.01 | 76.35 | 78.68 | 35 | SAM-Med2D |
| Datasets | Bbox prompt (%) | 1 point prompt (%) | ||||
|---|---|---|---|---|---|---|
| SAM | SAM-Med2D | SAM-Med2D* | SAM | SAM-Med2D | SAM-Med2D* | |
| CrossMoDA23 | 78.98 | 70.51 | 84.62 | 18.49 | 46.08 | 73.98 |
| KiTS23 | 84.80 | 76.32 | 87.93 | 38.93 | 48.81 | 79.87 |
| FLARE23 | 86.11 | 83.51 | 90.95 | 51.05 | 62.86 | 85.10 |
| ATLAS2023 | 82.98 | 73.70 | 86.56 | 46.89 | 34.72 | 70.42 |
| SEG2023 | 75.98 | 68.02 | 84.31 | 11.75 | 48.05 | 69.85 |
| LNQ2023 | 72.31 | 63.84 | 81.33 | 3.81 | 44.81 | 59.84 |
| CAS2023 | 52.34 | 46.11 | 60.38 | 0.45 | 28.79 | 15.19 |
| TDSC-ABUS2023 | 71.66 | 64.65 | 76.65 | 12.11 | 35.99 | 61.84 |
| ToothFairy2023 | 65.86 | 57.45 | 75.29 | 1.01 | 32.12 | 47.32 |
| Weighted sum | 85.35 | 81.93 | 90.12 | 48.08 | 60.31 | 83.41 |
👉 Visualization

👉 Test
Prepare your own dataset and refer to the samples in SAM-Med2D/data_demo to replace them according to your specific scenario. You need to generate the "label2image_test.json" file before running "test.py"
bash
cd ./SAM-Med2d
python test.py
- workdir: Specifies the working directory for the testing process. Default value is "workdir".
- batchsize: 1.
- imagesize: Default value is 256.
- boxesprompt: Use Bbox prompt to get segmentation results.
- pointnum: Specifies the number of points. Default value is 1.
- iterpoint: Specifies the number of iterations for point prompts.
- samcheckpoint: Load sam or sammed checkpoint.
- encoderadapter: Set to True if using SAM-Med2D's pretrained weights.
- savepred: Whether to save the prediction results.
- promptpath: Is there a fixed Prompt file? If not, the value is None, and it will be automatically generated in the latest prediction.
👉 Deploy
Export to ONNX
- export encoder model
bash
python3 scripts/export_onnx_encoder_model.py --sam_checkpoint /path/to/sam-med2d_b.pth --output /path/to/sam-med2d_b.encoder.onnx --model-type vit_b --image_size 256 --encoder_adapter True
- export decoder model
bash
python3 scripts/export_onnx_model.py --sam_checkpoint /path/to/sam-med2d_b.pth --output /path/to/sam-med2d_b.decoder.onnx --model-type vit_b --return-single-mask
- inference with onnxruntime
```
cd examples/SAM-Med2D-onnxruntime
python3 main.py --encodermodel /path/to/sam-med2db.encoder.onnx --decodermodel /path/to/sam-med2db.decoder.onnx ```
🚀 Try SAM-Med2D
- 🏆 Gradio Online: Online Demo can be found on OpenXLab.
- 🏆 Notebook Demo: You can use predictor_example.ipynb to run it locally to view the prediction results generated by different prompts.
- 🏆 Gradio Local: You can deploy app.ipynb locally and upload test cases.
- Notes: Welcome to feedback good case👍 and bad case👎 in issue.
🗓️ Ongoing
- [ ] Train code release
- [x] Test code release
- [x] Pre-trained model release
- [x] Paper release
- [x] Online Demo release
🎫 License
This project is released under the Apache 2.0 license.
💬 Discussion Group
If you have any questions about SAM-Med2D, feel free to join our WeChat group discussion:

🤝 Acknowledgement
- We thank all medical workers and dataset owners for making public datasets available to the community.
- Thanks to the open-source of the following projects: Segment Anything
👋 Hiring & Global Collaboration
- Hiring: We are hiring researchers, engineers, and interns in General Vision Group, Shanghai AI Lab. If you are interested in Medical Foundation Models and General Medical AI, including designing benchmark datasets, general models, evaluation systems, and efficient tools, please contact us.
- Global Collaboration: We're on a mission to redefine medical research, aiming for a more universally adaptable model. Our passionate team is delving into foundational healthcare models, promoting the development of the medical community. Collaborate with us to increase competitiveness, reduce risk, and expand markets.
- Contact: Junjun He(hejunjun@pjlab.org.cn), Jin Ye(yejin@pjlab.org.cn), and Tianbin Li (litianbin@pjlab.org.cn).
Reference
@misc{cheng2023sammed2d,
title={SAM-Med2D},
author={Junlong Cheng and Jin Ye and Zhongying Deng and Jianpin Chen and Tianbin Li and Haoyu Wang and Yanzhou Su and
Ziyan Huang and Jilong Chen and Lei Jiangand Hui Sun and Junjun He and Shaoting Zhang and Min Zhu and Yu Qiao},
year={2023},
eprint={2308.16184},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
Owner
- Name: CVHub
- Login: CVHub520
- Kind: user
- Company: CVHub
- Website: https://github.com/CVHub520
- Repositories: 10
- Profile: https://github.com/CVHub520
Welcome to CVHub!
GitHub Events
Total
- Fork event: 1
Last Year
- Fork event: 1