Your workflow sounds right and this code snippet should work:
h, w = 3, 3
mask = torch.randint(0, 7, (1, h, w))

res = torch.zeros(7, h, w)
res.scatter_(0, mask, 1.)

Could you check it locally and verify, that the result contains the expected values?