Draw semantic segmentation predictions/labels. Args: sem_seg (Tensor or ndarray): the segmentation of shape (H, W). Each value is the integer label of the pixel. area_threshold (int): segments with less than `area_threshold` are not drawn.
(self, sem_seg, area_threshold=None, alpha=0.7)
| 445 | return self.output |
| 446 | |
| 447 | def draw_sem_seg(self, sem_seg, area_threshold=None, alpha=0.7): |
| 448 | """ |
| 449 | Draw semantic segmentation predictions/labels. |
| 450 | |
| 451 | Args: |
| 452 | sem_seg (Tensor or ndarray): the segmentation of shape (H, W). |
| 453 | Each value is the integer label of the pixel. |
| 454 | area_threshold (int): segments with less than `area_threshold` are not drawn. |
| 455 | alpha (float): the larger it is, the more opaque the segmentations are. |
| 456 | |
| 457 | Returns: |
| 458 | output (VisImage): image object with visualizations. |
| 459 | """ |
| 460 | if isinstance(sem_seg, torch.Tensor): |
| 461 | sem_seg = sem_seg.numpy() |
| 462 | labels, areas = np.unique(sem_seg, return_counts=True) |
| 463 | sorted_idxs = np.argsort(-areas).tolist() |
| 464 | labels = labels[sorted_idxs] |
| 465 | for label in filter(lambda l: l < len(self.metadata.stuff_classes), labels): |
| 466 | try: |
| 467 | mask_color = [x / 255 for x in self.metadata.stuff_colors[label]] |
| 468 | except (AttributeError, IndexError): |
| 469 | mask_color = None |
| 470 | |
| 471 | binary_mask = (sem_seg == label).astype(np.uint8) |
| 472 | text = self.metadata.stuff_classes[label] |
| 473 | self.draw_binary_mask( |
| 474 | binary_mask, |
| 475 | color=mask_color, |
| 476 | edge_color=_OFF_WHITE, |
| 477 | text=text, |
| 478 | alpha=alpha, |
| 479 | area_threshold=area_threshold, |
| 480 | ) |
| 481 | return self.output |
| 482 | |
| 483 | def draw_panoptic_seg(self, panoptic_seg, segments_info, area_threshold=None, alpha=0.7): |
| 484 | """ |
no test coverage detected