    def visualize(
        self, detections, output_path="./tmp/outputs", thickness=1, mask_thresh=0.5
    ):
        """
        Visualize the outputs.
        """
        os.makedirs(output_path, exist_ok=True)
        meta_data = _get_coco_instances_meta()
        thing_colors = meta_data["thing_colors"]
        thing_classes = meta_data["thing_classes"]
        for file_name, result in detections.items():
            img = result["image"]
            boxes = result["boxes"]
            classes = result["classes"]
            scores = result["scores"]
            for pred_box, pred_class, pred_score in zip(boxes, classes, scores):
                box = pred_box.astype("int")
                start_point = (box[0], box[1])
                end_point = (box[2], box[3])
                color = tuple(thing_colors[pred_class])
                img = cv2.rectangle(img, start_point, end_point, color, thickness)
                text = thing_classes[pred_class] + ": " + str(pred_score)
                img = cv2.putText(
                    img,
                    text,
                    (box[0], box[1] - 10),
                    cv2.FONT_HERSHEY_SIMPLEX,
                    0.4,
                    color,
                    thickness,
                )

            if self.mask_on:
                masks = result["masks"]
                im_height, im_width = img.shape[:2]
                for pred_box, pred_class, mask in zip(boxes, classes, masks):
                    np_color = np.array(thing_colors[pred_class]) / 255
                    if im_height > im_width:
                        mask = np.rot90(mask, k=-1)
                    box = pred_box.astype("int")
                    det_width = box[2] - box[0]
                    det_height = box[3] - box[1]
                    mask = mask.astype(np.float32)
                    small_mask = Image.fromarray(mask)
                    mask = small_mask.resize(
                        (det_width, det_height), resample=self.interp_method
                    )
                    mask = np.array(mask, copy=False)
                    mask = np.array(mask > mask_thresh, dtype=np.uint8)
                    padded_mask = np.zeros((im_height, im_width), dtype=np.uint8)
                    x_0 = max(box[0], 0)
                    x_1 = min(box[2], im_width)
                    y_0 = max(box[1], 0)
                    y_1 = min(box[3], im_height)
                    padded_mask[y_0:y_1, x_0:x_1] = mask[
                        (y_0 - box[1]) : (y_1 - box[1]), (x_0 - box[0]) : (x_1 - box[0])
                    ]
                    img = Predictor.overlay(img, padded_mask, np_color)
            cv2.imwrite(os.path.join(output_path, file_name), img)
Visualize the outputs.
examples/02_detectron2/predictor/predictor.py