When using CrossEntropyLoss for segmentation,How to encode labels into single channel target image if value <= C is a must-be?

You would treat the background as a separate class, thus your target mask will have values in the range [0, 4].