This is a simple inference script for MedSAM2.
Clone the repository:
git clone https://github.com/JoshuaSiraj/medsam2_inference.git
cd medsam2_inferenceClone the MedSAM2 repository, while in the medsam2_inference directory:
git clone https://github.com/bowang-lab/MedSAM2.gitThis project uses Pixi to manage dependencies. Install it by following the instructions here.
Install the dependencies by running:
pixi installThe weights for MedSAM2 are not included in this repository. You can download them by running the following command:
pixi run download-weightsfrom inference import MedSAM3DInference, MedSAM3DInferenceConfig
config = MedSAM3DInferenceConfig(
dataset_csv="data/dataset.csv",
model_config_path="configs/sam2.1_hiera_t512.yaml",
checkpoint_path="checkpoints/MedSAM2_latest.pt",
output_dir="output",
window_level=500.0,
window_width=2500.0,
)
inference_module = MedSAM3DInference(config)
inference_module.run()- GPU is required.
- Performance is reliant on the right window level and width. Therefore only one Region of Interest (ROI) should be present in the mask.
ID,image_path,mask_path
1,/path/to/image.nii.gz,/path/to/mask.nii.gz
2,/path/to/image.nii.gz,/path/to/mask.nii.gz