Hello @tom
from torch.nn.functional import one_hot
seg = seg_3d.get_data() # 3D numpy array with 9 different values
num_labels = len(np.unique(seg)) # 9
seg = torch.tensor(seg).to(torch.int64)
seg_hot = one_hot(seg, num_labels)
print(seg_hot.shape, torch.unique(seg_hot))

with the codes I get the following error:
    seg_hot = one_hot(seg, num_labels)
RuntimeError: Class values must be smaller than num_classes.

Looks like they discussed the issue here: torch.nn.functional.one_hot should gracefully skip negative and out-of-range indices · Issue #45352 · pytorch/pytorch · GitHub 3
But found no alternates or solutions.
I think some of the class value e.g. 56, 11 or 10 are higher than the number of classes(9), that results in the error.