Hi,
I was trying to convert a numpy array, as shown in the cell below, to a one-hot encoded vector. The shape of the input gt_arr is [N, H, W] and I wanted it to convert to [N,3,H,W] using the command below:
gt_arr_hot = nn.functional.one_hot(torch.from_numpy(gt_arr).to(torch.int64), num_classes=3).permute(0,3,1,2)
I get some weird output as show below:
Input:
np.unique(gt_arr) ---> array([0, 1, 2], dtype=uint8)
Output:
gt_arr_hot.unique() ---> tensor([ 0, 1, 281474976710656, 2251799813685248, 4503599627370496, 4503599627370497, 9007199254740992, 9007199254740993, 18014398509481984, 18014398509481985, 22517998136852480, 36028797018963968]
It doesn’t happen often but it happens randomly on some arrays. Am I doing something wrong here? Any help is much appreciated. Thank you in advance! and excuse me for my formatting skills.
Pytorch version 1.7.1