MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / draw_panoptic_seg

Method draw_panoptic_seg

utils/visualizer.py:483–546  ·  view source on GitHub ↗

Draw panoptic prediction annotations or results. Args: panoptic_seg (Tensor): of shape (height, width) where the values are ids for each segment. segments_info (list[dict] or None): Describe each segment in `panoptic_seg`. If

(self, panoptic_seg, segments_info, area_threshold=None, alpha=0.7)

Source from the content-addressed store, hash-verified

481 return self.output
482
483 def draw_panoptic_seg(self, panoptic_seg, segments_info, area_threshold=None, alpha=0.7):
484 """
485 Draw panoptic prediction annotations or results.
486
487 Args:
488 panoptic_seg (Tensor): of shape (height, width) where the values are ids for each
489 segment.
490 segments_info (list[dict] or None): Describe each segment in `panoptic_seg`.
491 If it is a ``list[dict]``, each dict contains keys "id", "category_id".
492 If None, category id of each pixel is computed by
493 ``pixel // metadata.label_divisor``.
494 area_threshold (int): stuff segments with less than `area_threshold` are not drawn.
495
496 Returns:
497 output (VisImage): image object with visualizations.
498 """
499 pred = _PanopticPrediction(panoptic_seg, segments_info, self.metadata)
500
501 if self._instance_mode == ColorMode.IMAGE_BW:
502 self.output.reset_image(self._create_grayscale_image(pred.non_empty_mask()))
503
504 # draw mask for all semantic segments first i.e. "stuff"
505 for mask, sinfo in pred.semantic_masks():
506 category_idx = sinfo["category_id"]
507 try:
508 mask_color = [x / 255 for x in self.metadata.stuff_colors[category_idx]]
509 except AttributeError:
510 mask_color = None
511
512 text = self.metadata.stuff_classes[category_idx].replace('-other','').replace('-merged','')
513 self.draw_binary_mask(
514 mask,
515 color=mask_color,
516 edge_color=_OFF_WHITE,
517 text=text,
518 alpha=alpha,
519 area_threshold=area_threshold,
520 )
521
522 # draw mask for all instances second
523 all_instances = list(pred.instance_masks())
524 if len(all_instances) == 0:
525 return self.output
526 masks, sinfo = list(zip(*all_instances))
527 category_ids = [x["category_id"] for x in sinfo]
528
529 try:
530 scores = [x["score"] for x in sinfo]
531 except KeyError:
532 scores = None
533 class_names = [name.replace('-other','').replace('-merged','') for name in self.metadata.thing_classes]
534 labels = _create_text_labels(
535 category_ids, scores, class_names, [x.get("iscrowd", 0) for x in sinfo]
536 )
537
538 try:
539 colors = [
540 self._jitter([x / 255 for x in self.metadata.thing_colors[c]]) for c in category_ids

Callers 1

draw_dataset_dictMethod · 0.95

Calls 10

draw_binary_maskMethod · 0.95
_jitterMethod · 0.95
overlay_instancesMethod · 0.95
_PanopticPredictionClass · 0.85
_create_text_labelsFunction · 0.85
reset_imageMethod · 0.80
non_empty_maskMethod · 0.80
semantic_masksMethod · 0.80
instance_masksMethod · 0.80

Tested by

no test coverage detected