Mapping the Label Image to Class Index For Semantic Segmentation

I assume you are referring to this post.

Try to adapt the code to your use case and make sure you are dealing with the same data shapes (i.e. check for the same dimension layout etc.).
One possible reason for a lot of unique colors could be the usage of an interpolation method while resizing other than nearest neighbors.