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

Yes, my linked code snippet gets all unique colors from the image.

[...]
# Get color codes for dataset (maybe you would have to use more than a single
# image, if it doesn't contain all classes)
target = torch.from_numpy(target)
colors = torch.unique(target.view(-1, target.size(2)), dim=0).numpy()
[...]