SAM/SAM 2, how to generate feature embedings and run inference based on the embedings

the inference process of SAM has 2 main stages, (1) Generated image embedding, (2) Generated mask based on prompt.
(1) takes up most of the compute time, so it is a common practice to run (1) once and (2) multiple times, for interactive GUIs

does the ultralytics package support this use case

1 Like

You can use set_image

model.predictor.set_image("image.jpg")
embeddings = model.predictor.features

Check this too:

2 Likes