open-mmlab / playground

A central hub for gathering and showcasing amazing projects that extend OpenMMLab with SAM and other exciting features.
Apache License 2.0
1.1k stars 122 forks source link

Memory issues after auto-annotating for a few objects #150

Open renyiyu opened 1 year ago

renyiyu commented 1 year ago

Label Studio X SAM seems to have memory issues after auto annotating for about 20-30 objects in the same image. The auto annotating process is getting slower and slower even I use vit_b/mobile sam model on gpu setup.

My average image size is around 640 * 640 and my GPU is 3090. Since my use case has around 100 small objects to annotate per image. It makes me really difficult to annotate all the objects for the entire image, especially last 50 objects.

JimmyMa99 commented 1 year ago

This issue was also mentioned, and I'm guessing it's a label studio issue, the exact problem needs further troubleshooting.

halqadasi commented 5 months ago

I solved this issue by loading the model only one time if it has not been loaded before rather than loading the model by labeling each image.

Open /playground/label_anything/sam and open the mmdetection.py and go to the class MMDetectionand change it as follows:


class MMDetection(LabelStudioMLBase):
    """Object detector based on https://github.com/open-mmlab/mmdetection."""
    _predictor = None                  # ----------> add this private variable
    def __init__(self,
                 config_file=None,
                 checkpoint_file=None,
                 sam_config='vit_b',
                 sam_checkpoint_file=None,
                 image_dir=None,
                 labels_file=None,
                 out_mask=True,
                 out_bbox=False,
                 out_poly=False,
                 score_threshold=0.5,
                 device='cpu',
                 **kwargs):

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

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

        self.PREDICTOR = MMDetection._predictor