Draw instance-level prediction results on an image. Args: predictions (Instances): the output of an instance detection/segmentation model. Following fields will be used to draw: "pred_boxes", "pred_classes", "scores", "pred_masks" (or "pr
(self, predictions)
| 382 | self.keypoint_threshold = _KEYPOINT_THRESHOLD |
| 383 | |
| 384 | def draw_instance_predictions(self, predictions): |
| 385 | """ |
| 386 | Draw instance-level prediction results on an image. |
| 387 | |
| 388 | Args: |
| 389 | predictions (Instances): the output of an instance detection/segmentation |
| 390 | model. Following fields will be used to draw: |
| 391 | "pred_boxes", "pred_classes", "scores", "pred_masks" (or "pred_masks_rle"). |
| 392 | |
| 393 | Returns: |
| 394 | output (VisImage): image object with visualizations. |
| 395 | """ |
| 396 | boxes = predictions.pred_boxes if predictions.has("pred_boxes") else None |
| 397 | scores = predictions.scores if predictions.has("scores") else None |
| 398 | classes = predictions.pred_classes.tolist() if predictions.has("pred_classes") else None |
| 399 | labels = _create_text_labels(classes, scores, self.metadata.get("thing_classes", None)) |
| 400 | keypoints = predictions.pred_keypoints if predictions.has("pred_keypoints") else None |
| 401 | |
| 402 | keep = (scores > 0.5).cpu() |
| 403 | boxes = boxes[keep] |
| 404 | scores = scores[keep] |
| 405 | classes = np.array(classes) |
| 406 | classes = classes[np.array(keep)] |
| 407 | labels = np.array(labels) |
| 408 | labels = labels[np.array(keep)] |
| 409 | |
| 410 | if predictions.has("pred_masks"): |
| 411 | masks = np.asarray(predictions.pred_masks) |
| 412 | masks = masks[np.array(keep)] |
| 413 | masks = [GenericMask(x, self.output.height, self.output.width) for x in masks] |
| 414 | else: |
| 415 | masks = None |
| 416 | |
| 417 | if self._instance_mode == ColorMode.SEGMENTATION and self.metadata.get("thing_colors"): |
| 418 | # if self.metadata.get("thing_colors"): |
| 419 | colors = [ |
| 420 | self._jitter([x / 255 for x in self.metadata.thing_colors[c]]) for c in classes |
| 421 | ] |
| 422 | alpha = 0.4 |
| 423 | else: |
| 424 | colors = None |
| 425 | alpha = 0.4 |
| 426 | |
| 427 | if self._instance_mode == ColorMode.IMAGE_BW: |
| 428 | self.output.reset_image( |
| 429 | self._create_grayscale_image( |
| 430 | (predictions.pred_masks.any(dim=0) > 0).numpy() |
| 431 | if predictions.has("pred_masks") |
| 432 | else None |
| 433 | ) |
| 434 | ) |
| 435 | alpha = 0.3 |
| 436 | |
| 437 | self.overlay_instances( |
| 438 | masks=masks, |
| 439 | boxes=boxes, |
| 440 | labels=labels, |
| 441 | keypoints=keypoints, |
nothing calls this directly
no test coverage detected