Skip to content

Commit 5c9e0d9

Browse files
bowenc0221facebook-github-bot
authored andcommitted
Visualization of the new panoptic output format
Summary: Currently only supports visualization of the new output format. The masks for `stuff` classes are still not shown, but I think this is an old issue. TEST=python demo/demo.py --config-file projects/Panoptic-DeepLab/configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024.yaml --input ~/github/detectron2/datasets/cityscapes/leftImg8bit/test/berlin/berlin_000030_000019_leftImg8bit.png --output projects/output/vis --opts MODEL.WEIGHTS /checkpoint/bowencheng/experiments/30841561/output/model_final.pth ![vis](https://user-images.githubusercontent.com/25308473/94322846-8c9c4080-ff48-11ea-925c-0b9fe6bfca40.png) Pull Request resolved: fairinternal/detectron2#463 Reviewed By: ppwwyyxx Differential Revision: D23956202 Pulled By: bowenc0221 fbshipit-source-id: efdd21aae470c067da03099e47fef34b47e6f38b
1 parent 429f33e commit 5c9e0d9

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

demo/demo.py

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
def setup_cfg(args):
2121
# load config from file and command-line arguments
2222
cfg = get_cfg()
23+
# To use demo for Panoptic-DeepLab, please uncomment the following two lines.
24+
# from detectron2.projects.panoptic_deeplab import add_panoptic_deeplab_config # noqa
25+
# add_panoptic_deeplab_config(cfg)
2326
cfg.merge_from_file(args.config_file)
2427
cfg.merge_from_list(args.opts)
2528
# Set score_threshold for builtin models

detectron2/utils/video_visualizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def draw_panoptic_seg_predictions(
125125
self, frame, panoptic_seg, segments_info, area_threshold=None, alpha=0.5
126126
):
127127
frame_visualizer = Visualizer(frame, self.metadata)
128-
pred = _PanopticPrediction(panoptic_seg, segments_info)
128+
pred = _PanopticPrediction(panoptic_seg, segments_info, self.metadata)
129129

130130
if self._instance_mode == ColorMode.IMAGE_BW:
131131
frame_visualizer.output.img = frame_visualizer._create_grayscale_image(

detectron2/utils/visualizer.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,30 @@ def bbox(self):
147147

148148

149149
class _PanopticPrediction:
150-
def __init__(self, panoptic_seg, segments_info):
150+
def __init__(self, panoptic_seg, segments_info, metadata=None):
151+
if segments_info is None:
152+
assert metadata is not None
153+
# If "segments_info" is None, we assume "panoptic_img" is a
154+
# H*W int32 image storing the panoptic_id in the format of
155+
# category_id * label_divisor + instance_id. We reserve -1 for
156+
# VOID label.
157+
label_divisor = metadata.label_divisor
158+
segments_info = []
159+
for panoptic_label in np.unique(panoptic_seg.numpy()):
160+
if panoptic_label == -1:
161+
# VOID region.
162+
continue
163+
pred_class = panoptic_label // label_divisor
164+
isthing = pred_class in metadata.thing_dataset_id_to_contiguous_id.values()
165+
segments_info.append(
166+
{
167+
"id": int(panoptic_label),
168+
"category_id": int(pred_class),
169+
"isthing": bool(isthing),
170+
}
171+
)
172+
del metadata
173+
151174
self._seg = panoptic_seg
152175

153176
self._sinfo = {s["id"]: s for s in segments_info} # seg id -> seg info
@@ -433,7 +456,7 @@ def draw_panoptic_seg_predictions(
433456
Returns:
434457
output (VisImage): image object with visualizations.
435458
"""
436-
pred = _PanopticPrediction(panoptic_seg, segments_info)
459+
pred = _PanopticPrediction(panoptic_seg, segments_info, self.metadata)
437460

438461
if self._instance_mode == ColorMode.IMAGE_BW:
439462
self.output.img = self._create_grayscale_image(pred.non_empty_mask())
@@ -470,7 +493,9 @@ def draw_panoptic_seg_predictions(
470493
labels = _create_text_labels(category_ids, scores, self.metadata.thing_classes)
471494

472495
try:
473-
colors = [random_color(rgb=True, maximum=1) for k in category_ids]
496+
colors = [
497+
self._jitter([x / 255 for x in self.metadata.thing_colors[c]]) for c in category_ids
498+
]
474499
except AttributeError:
475500
colors = None
476501
self.overlay_instances(masks=masks, labels=labels, assigned_colors=colors, alpha=alpha)

0 commit comments

Comments
 (0)