facebookresearch / Mask2Former

Code release for "Masked-attention Mask Transformer for Universal Image Segmentation"
MIT License
2.59k stars 388 forks source link

Running mask2former without a GPU #169

Open AliAlfatemi opened 1 year ago

AliAlfatemi commented 1 year ago

Hello, I am trying to run mask2former on my local laptop, but it requires a GPU which I do not have. I know that I can run it using Google Colab, but I am unfamiliar with how to use the platform and am not sure if I can manipulate the package in order to visualize the mask binary for the main object in the image. If I do not have a GPU on my computer, what are my options for running mask2former and manipulating the package as I need to? Can you please advise me on what to do in this situation?

yogeshchandrasekharuni commented 1 year ago

You can set cfg.MODEL.DEVICE = "cpu" before you load your Predictor

Example:

class Foo:
    def __init__(self):
        cfg = get_cfg()
        add_deeplab_config(cfg)
        add_maskformer2_config(cfg)
        cfg.merge_from_file("./ai/image_segmentation/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml")
        cfg.MODEL.WEIGHTS = 'https://dl.fbaipublicfiles.com/maskformer/mask2former/coco/panoptic/maskformer2_swin_large_IN21k_384_bs16_100ep/model_final_f07440.pkl'
        cfg.MODEL.MASK_FORMER.TEST.SEMANTIC_ON = True
        cfg.MODEL.MASK_FORMER.TEST.INSTANCE_ON = True
        cfg.MODEL.MASK_FORMER.TEST.PANOPTIC_ON = True
        cfg.MODEL.DEVICE = "cpu"
        self.predictor = DefaultPredictor(cfg)