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

[fix] Prevent Out-of-Memory Errors #180

Open
wants to merge 1 commit 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
12 changes: 8 additions & 4 deletions label_anything/sam/mmdetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def load_my_model(
class MMDetection(LabelStudioMLBase):
"""Object detector based on https://github.com/open-mmlab/mmdetection."""

_predictor = None
def __init__(self,
model_name="sam_hq",
config_file=None,
Expand All @@ -78,10 +79,13 @@ def __init__(self,
**kwargs):

super(MMDetection, self).__init__(**kwargs)

PREDICTOR = load_my_model(
model_name, device, sam_config, sam_checkpoint_file)
self.PREDICTOR = PREDICTOR

# Only load the model if it hasn't been loaded before
if MMDetection._predictor is None:
MMDetection._predictor = load_my_model(
model_name, device, sam_config, sam_checkpoint_file)

self.PREDICTOR = MMDetection._predictor

self.out_mask = out_mask
self.out_bbox = out_bbox
Expand Down