Dear @KFrank.

I remake the target as [batch, nClasses, H, W], being nClasses = 5. I split  the objects labels along layers as follows (but I don’t know if it is correct):

Layer 0: image with all  pixels value to zero, label 0 = background
Layer 1:  pixels value to 1 for object 1 (e.g. dog), and 0s for the background
Layer 2:  pixels value to 2 for object 2 (e.g. cat), and 0s for the background
and son on.
is it a reasonable model for the layers in semantic segmentation?

However a get a new error:

RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [4, 5, 224, 224] ,
I use batchsize=5, nClasses=1.  The input data is [4,1,224,244] aiming to obtain [4,5,224,244],