Views
No views yet
1# Using huggingface_hub
2from huggingface_hub import hf_hub_download
3
4# Download the recommended latest model
5model_path = hf_hub_download(repo_id="wanglab/MedSAM2", filename="MedSAM2_latest.pt")
6
7# Or download a specific fine-tuned model
8heart_us_model_path = hf_hub_download(repo_id="wanglab/MedSAM2", filename="MedSAM2_US_Heart.pt")
9liver_model_path = hf_hub_download(repo_id="wanglab/MedSAM2", filename="MedSAM2_MRI_LiverLesion.pt")1from huggingface_hub import hf_hub_download
2import os
3
4# Create checkpoints directory if it doesn't exist
5os.makedirs("checkpoints", exist_ok=True)
6
7# List of model filenames
8model_files = [
9 "MedSAM2_2411.pt",
10 "MedSAM2_US_Heart.pt",
11 "MedSAM2_MRI_LiverLesion.pt",
12 "MedSAM2_CTLesion.pt",
13 "MedSAM2_latest.pt"
14]
15
16# Download all models
17for model_file in model_files:
18 local_path = os.path.join("checkpoints", model_file)
19 hf_hub_download(
20 repo_id="wanglab/MedSAM2",
21 filename=model_file,
22 local_dir="checkpoints",
23 local_dir_use_symlinks=False
24 )
25 print(f"Downloaded {model_file} to {local_path}")@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}
}