How would you like to ignore the class in your one-hot encoded tensor?
Do you want to remove it completely?
This code should just remove the unwanted class channel:
batch_size = 10
n_classes = 5
h, w = 24, 24
labels = torch.empty(batch_size, 1, h, w, dtype=torch.long).random_(n_classes)
one_hot = torch.zeros(batch_size, n_classes, h, w)

one_hot.scatter_(1, labels, 1)
one_hot = one_hot[:, :n_classes-1]