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

Created Export & Import for img embedding #397

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sam2/sam2_image_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,22 @@ def get_image_embedding(self) -> torch.Tensor:
def device(self) -> torch.device:
return self.model.device

def import_fields(self, fields):
self._features = fields["_features"]
self._orig_hw = fields["_orig_hw"]
self._is_image_set = True

def export_fields(self):
"""
Exports the specified fields of the TestSamPredictor class.
Returns:
dict: A dictionary containing the values of features, orig_h, orig_w, input_h, and input_w.
"""
return {
"_features": self._features,
"_orig_hw": self._orig_hw
}

def reset_predictor(self) -> None:
"""
Resets the image embeddings and other state variables.
Expand Down