How to convert RGB images with many different colors (not only red, green, blue) into classes for segmentation training?, The mask is linked below

Actually i was expecting number of classes to be 50-100 because im sure there are not more than 100 objects in each image. Please let me know if im doing something wrong.
I actually checked it again and im getting around 500, which is also not possible.
np.unique function returns me a 256 value which seems realistic. and i feel its correct too.

I still didnt get what do you mean by " and contain class indices in the range `[0, nb_classes-1]" im hoping that your code will output me the target values in this format.
Because im getting this error,
input and target batch or spatial sizes don’t match: target [1 x 3 x 896], input [1 x 256 x 896 x 896] at /pytorch/aten/src/THCUNN/generic/SpatialClassNLLCriterion.cu:23