Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading embeddings to speed up video predictions #565

Open
jfoody-centaur opened this issue Feb 7, 2025 · 0 comments
Open

Loading embeddings to speed up video predictions #565

jfoody-centaur opened this issue Feb 7, 2025 · 0 comments

Comments

@jfoody-centaur
Copy link

jfoody-centaur commented Feb 7, 2025

For the SAM2 image predictor, I created a custom initialization of the image predictor which can save/load the image embeddings to speed up the process when those images are called for prediction again.

I'm interested in doing something similar for the SAM2 video predictor where I preload the embeddings for all frames. Is this (or something similar) possible for the video predictor as the embeddings/memory attention seem to differ from the image predictor.

I'm also having trouble getting the model to initialize correctly with a custom initialization using something like this:

class MySamVideo(SAM2VideoPredictor):
    def __init__(self, model, **kwargs):
        # Extract required attributes from `model` if available
        extracted_args = {
            "image_encoder": getattr(model, "image_encoder", None),
            "memory_attention": getattr(model, "memory_attention", None),
            "memory_encoder": getattr(model, "memory_encoder", None)
        }

        super().__init__(**extracted_args, **kwargs)
        self.model = model

    def save_image_embedding(self, path):
        # Save existing embeddings

    def load_image_embedding(self, path):
        # Check if embedding exists & load

# called like this
sam = build_sam2_video_predictor(model_cfg, model_path, device=device)
sam.to(device=device)
model = MySamVideo(sam)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant