How can I get loss in this case?

Hi I am a pytorch newbie

I tried 3D deeplearning and I got first batch’s outputs and labels.

outputs : torch.Size([32, 4])
labels : torch.Size([32, 4])
outputs : tensor([[ 0.6386, 0.8804, 0.0802, -0.6856],
[ 1.5065, 0.8598, 1.0433, -2.3924],
[ 0.0379, 3.3215, -0.5928, 0.2159],
[ 0.9913, 3.5304, 0.0685, -1.3560],
[-0.2051, 2.9849, -0.7657, -0.8725],
[ 1.3075, 1.9554, -0.1340, -1.2231],
[ 1.3540, 2.2120, -0.1225, -2.0182],
[ 0.9369, -0.4576, -0.5696, -0.6731],
[ 1.0587, 2.2184, 0.7369, 0.5067],
[ 0.1577, 1.1418, -0.5708, -1.6497],
[-0.3060, 1.7785, -0.5178, -2.0496],
[ 1.1665, 1.7909, -0.2612, -3.2435],
[ 3.6382, 2.4487, -2.4305, -6.0900],
[-0.3202, 1.3922, -0.3043, -2.9920],
[-0.3049, 2.3529, -0.5429, -1.2844],
[-0.2010, 2.0226, -0.9945, -0.9781],
[ 0.1318, 1.9036, -0.6613, -1.8101],
[ 0.3844, 1.9908, -0.1160, -1.3563],
[ 0.5801, 0.9606, -0.1840, -0.6442],
[ 1.3811, 1.4375, 0.9490, -1.5605],
[ 0.6690, 1.6736, 0.3756, -1.3233],
[-0.4796, 0.7052, -0.7644, 0.4543],
[ 0.0512, 0.9333, 1.0720, -0.9512],
[-0.2501, 1.5006, -0.5616, -1.1430],
[-0.8548, 3.5933, -0.1623, -2.5032],
[ 0.5080, 2.9712, -0.9497, -2.4739],
[ 0.6291, 1.5536, 0.4837, -2.5471],
[ 2.3567, 2.0164, 0.6488, -3.2746],
[ 1.1576, 1.3680, -0.0774, -1.6563],
[ 0.1288, 0.7665, -0.1139, 0.3316],
[ 0.3624, 2.1957, 0.8695, -0.9878],
[ 0.0497, 1.1887, -0.4944, -1.7466]], device=‘cuda:0’,
grad_fn=)
labels : tensor([[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0]], device=‘cuda:0’)

my loss func is CrossEntropyLoss()
I got error “multi-target not supported at C:/cb/pytorch_1000000000000/work/aten/src\THCUNN/generic/ClassNLLCriterion.cu:18”

Help me bros… thanks

nn.CrossEntropyLoss expects class indices, while your target is one-hot encoded.
Use target = torch.argmax(target, dim=1) to create the expected target tensor.

batch_size = 32

thanks, I used It
target = torch.argmax(target, dim=1)
=>
tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1], device=‘cuda:0’)

but It is disappear class information
[1, 0, 0, 0], => class 1
[0, 1, 0, 0], => class 2
[0, 0, 1, 0], => class 3
[0, 0, 0, 1], => class 4

Your posted labels tensor only contains class0 and class1, so the output is expected.

Thank you. I respect you.