I am really new to coding, right now I am trying to turn my label to one hot encoding. I have already done transferring the np.array to tensor as shown below
tensor([4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 3., 3., 3., 3., 3., 3.,
3., 3., 3., 3., 3., 3., 3., 3., 3., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2.], dtype=torch.float64)
and I am using code to do one hot encoding
aaa = F.one_hot(torch_qyh, num_classes=5)
However, there is an error showing "RuntimeError: one_hot is only applicable to index tensor." Any help would appreciated.
You will have to convert it in long type. Can't do it with float. F.one_hot only takes LongTensor.
F.one_hot(t.long())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With