How to prepare training data for deep learning models
You can create a mask image with the background having value 0 and give all pixels the value of its class.

I am not sure what approach you are taking, but you can for example use Convolutional Neural Networks. They will learn from the mask image what features contribute to a pixel class and can therefore, at inference time, output a per pixel class probability.