Skip to content

Commit ecc0856

Browse files
add color field in instances and visualize based on preset colors
Summary: Pull Request resolved: #3549 Currently D2 (11528ce) and D2 (11528ce083dc9ff83ee3a8f9086a1ef54d2a402f)GO uses a box IoU based method to assign id and color for each instance. It is useful but not flexible. This diff allows user to define their own preset colors for each instance. By doing this, some advanced tracking method can be applied before get into the Visualizer. Reviewed By: FCChen Differential Revision: D31366663 fbshipit-source-id: e04d26475c2935439a045e96c28f4391e21d40f1
1 parent f5e4c45 commit ecc0856

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

detectron2/utils/video_visualizer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def draw_instance_predictions(self, frame, predictions):
7272
scores = predictions.scores if predictions.has("scores") else None
7373
classes = predictions.pred_classes.numpy() if predictions.has("pred_classes") else None
7474
keypoints = predictions.pred_keypoints if predictions.has("pred_keypoints") else None
75+
colors = predictions.COLOR if predictions.has("COLOR") else [None] * len(predictions)
7576

7677
if predictions.has("pred_masks"):
7778
masks = predictions.pred_masks
@@ -82,10 +83,11 @@ def draw_instance_predictions(self, frame, predictions):
8283
masks = None
8384

8485
detected = [
85-
_DetectedInstance(classes[i], boxes[i], mask_rle=None, color=None, ttl=8)
86+
_DetectedInstance(classes[i], boxes[i], mask_rle=None, color=colors[i], ttl=8)
8687
for i in range(num_instances)
8788
]
88-
colors = self._assign_colors(detected)
89+
if not predictions.has("COLOR"):
90+
colors = self._assign_colors(detected)
8991

9092
labels = _create_text_labels(classes, scores, self.metadata.get("thing_classes", None))
9193

0 commit comments

Comments
 (0)