ColorMode(1)
only has an effect if the metadata passed to the Visualizer
has thing_colors
defined. From the documentation for ColorMode,
SEGMENTATION= 1
Let instances of the same category have similar colors
(from metadata.thing_colors), and overlay them with high opacity. This
provides more attention on the quality of segmentation.
So, you need to add a list of pre-defined colors (one for each class) to your metadata. From here,
thing_colors
(list[tuple(r, g, b)]): Pre-defined color (in [0, 255]) for each thing category. Used for visualization. If not given, random colors will be used.
Now, the actual colors used may not be the exact same ones as specified in thing_colors
. In Visualizer.draw_instance_predictions()
, each specified color is jittered by adding a random value to it, so the overlaid color is a slightly different one. This use of a random value means that you will still see class colors change between frames. Depending on the colors you specify, this change may or may not be visually obvious.
A simple solution to this might be to subclass Visualizer
and override the _jitter()
method so that it returns the color as is.
class MyVisualizer(Visualizer):
def _jitter(self, color):
return color
However, _jitter()
is intended to be an internal method, so this is a hacky solution, and might break sometime down the line.
A better solution might be to override draw_instance_predictions()
and customize the drawing to your needs.