MedicineToken / Medical-SAM2

Medical SAM 2: Segment Medical Images As Video Via Segment Anything Model 2
Apache License 2.0
453 stars 57 forks source link

Is there any available code for inference? #24

Closed Moliang-Wange closed 2 months ago

Moliang-Wange commented 2 months ago

Hi there,

I'm currently working on a project to implement CT and MRI segmentation using this model. However, I've looked through the documentation and the examples provided in the repository, but I couldn't find a clear example of how to set up inference, especially for video segmentation.

Could you please let me know if there is any existing code or example notebooks for performing inference with the SAM2 model? Specifically, I'm looking for guidance on how to properly initialize the model components and run inference on video frames.

Thanks in advance for your help!

jiayuanz3 commented 2 months ago

yes, there are functions named validation_sam in the function.py and function.py, depends on your specific need for 2D or 3D. the most directly way is to comment out the lines related to train in train_2d.py or train_3d.py, only leave the validation_sam.

AlexanderZeilmann commented 2 months ago

I think @Moliang-Wange was looking for a simple solution like the five lines it takes to segment something with the original sam (at least that is what I am interested in):

from segment_anything import SamPredictor, sam_model_registry
sam = sam_model_registry["<model_type>"](checkpoint="<path/to/checkpoint>")
predictor = SamPredictor(sam)
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)

It would be nice to have a similar code snippet that is as simple as possible for using Medical-SAM2.