Solved by ptrblck in post #7 
              
              
                Since your current mask is a one-hot encoded tensor (each channel represents a class, where 1 denotes an active class), you could transform it into the desired class mask via: 
target = torch.argmax(mask, dim=1)

Note that dim=1 is used, if your channel dimension (class channels) is in dim1.