'COCO annotations to masks - For instance segmentation model training

I am trying to convert my COCO annotations to a mask. Each instance in the COCO annotations need to be represented as an unique instance in the mask. I found this question which does convert the annotations to a mask but there are only two unique instances of objects within the mask.

Here is an image of a mask. One can see that there are only two distinct instances (colors). I need every object to be a unique instance (color)

Is there another technique I can use to preserve ALL individual instances?

Many thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source