How would be the confidence of the mask be defined?
If you just want to keep the largest class index, you could use torch.max:
a = torch.randint(0, 4, (2, 4, 4))
b = torch.randint(0, 4, (2, 4, 4))
c = torch.max(a, b)