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

Method draw_dataset_dict

utils/visualizer.py:550–617  ·  view source on GitHub ↗

Draw annotations/segmentaions in Detectron2 Dataset format. Args: dic (dict): annotation/segmentation data of one image, in Detectron2 Dataset format. Returns: output (VisImage): image object with visualizations.

(self, dic)

Source from the content-addressed store, hash-verified

548 draw_panoptic_seg_predictions = draw_panoptic_seg # backward compatibility
549
550 def draw_dataset_dict(self, dic):
551 """
552 Draw annotations/segmentaions in Detectron2 Dataset format.
553
554 Args:
555 dic (dict): annotation/segmentation data of one image, in Detectron2 Dataset format.
556
557 Returns:
558 output (VisImage): image object with visualizations.
559 """
560 annos = dic.get("annotations", None)
561 if annos:
562 if "segmentation" in annos[0]:
563 masks = [x["segmentation"] for x in annos]
564 else:
565 masks = None
566 if "keypoints" in annos[0]:
567 keypts = [x["keypoints"] for x in annos]
568 keypts = np.array(keypts).reshape(len(annos), -1, 3)
569 else:
570 keypts = None
571
572 boxes = [
573 BoxMode.convert(x["bbox"], x["bbox_mode"], BoxMode.XYXY_ABS)
574 if len(x["bbox"]) == 4
575 else x["bbox"]
576 for x in annos
577 ]
578
579 colors = None
580 category_ids = [x["category_id"] for x in annos]
581 if self._instance_mode == ColorMode.SEGMENTATION and self.metadata.get("thing_colors"):
582 colors = [
583 self._jitter([x / 255 for x in self.metadata.thing_colors[c]])
584 for c in category_ids
585 ]
586 names = self.metadata.get("thing_classes", None)
587 labels = _create_text_labels(
588 category_ids,
589 scores=None,
590 class_names=names,
591 is_crowd=[x.get("iscrowd", 0) for x in annos],
592 )
593 self.overlay_instances(
594 labels=labels, boxes=boxes, masks=masks, keypoints=keypts, assigned_colors=colors
595 )
596
597 sem_seg = dic.get("sem_seg", None)
598 if sem_seg is None and "sem_seg_file_name" in dic:
599 with PathManager.open(dic["sem_seg_file_name"], "rb") as f:
600 sem_seg = Image.open(f)
601 sem_seg = np.asarray(sem_seg, dtype="uint8")
602 if sem_seg is not None:
603 self.draw_sem_seg(sem_seg, area_threshold=0, alpha=0.4)
604
605 pan_seg = dic.get("pan_seg", None)
606 if pan_seg is None and "pan_seg_file_name" in dic:
607 with PathManager.open(dic["pan_seg_file_name"], "rb") as f:

Callers

nothing calls this directly

Calls 5

_jitterMethod · 0.95
overlay_instancesMethod · 0.95
draw_sem_segMethod · 0.95
draw_panoptic_segMethod · 0.95
_create_text_labelsFunction · 0.85

Tested by

no test coverage detected