dangmanhtruong1995:

outputs[‘instances’].pred_masks.to(‘cpu’).numpy()


Here is the code (I used from https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=dq9GY37ml1kr 30):

import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
import numpy as np
import cv2
import random
import pdb
import matplotlib as mpl
mpl.use(‘Agg’)
import matplotlib.pyplot as plt
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file(“COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml”))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5  # set threshold for this model
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(“COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml”)
predictor = DefaultPredictor(cfg)
im = cv2.imread("./input.jpg")
outputs = predictor(im)
mask = outputs[‘instances’].pred_masks.to(‘cpu’).numpy()
pdb.set_trace()
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
v = v.draw_instance_predictions(outputs[“instances”].to(“cpu”))
cv2.imwrite(’./out.png’, v.get_image()[:, :, ::-1])

The image can be downloaded with:
wget http://images.cocodataset.org/val2017/000000439715.jpg -O input.jpg
The problem is that the mask variable only returns either 0 or 1, but I want the score for each pixel from 0 to 1 (because the Mask-RCNN paper returns so). Thank you very much.