How can I get loss in this case?

111394: <p>Hi  I am a pytorch newbie</p>
<p>I tried 3D deeplearning and I got first batch’s outputs and labels.</p>
<p>outputs :  torch.Size([32, 4])<br>
labels :  torch.Size([32, 4])<br>
outputs :  tensor([[ 0.6386,  0.8804,  0.0802, -0.6856],<br>
[ 1.5065,  0.8598,  1.0433, -2.3924],<br>
[ 0.0379,  3.3215, -0.5928,  0.2159],<br>
[ 0.9913,  3.5304,  0.0685, -1.3560],<br>
[-0.2051,  2.9849, -0.7657, -0.8725],<br>
[ 1.3075,  1.9554, -0.1340, -1.2231],<br>
[ 1.3540,  2.2120, -0.1225, -2.0182],<br>
[ 0.9369, -0.4576, -0.5696, -0.6731],<br>
[ 1.0587,  2.2184,  0.7369,  0.5067],<br>
[ 0.1577,  1.1418, -0.5708, -1.6497],<br>
[-0.3060,  1.7785, -0.5178, -2.0496],<br>
[ 1.1665,  1.7909, -0.2612, -3.2435],<br>
[ 3.6382,  2.4487, -2.4305, -6.0900],<br>
[-0.3202,  1.3922, -0.3043, -2.9920],<br>
[-0.3049,  2.3529, -0.5429, -1.2844],<br>
[-0.2010,  2.0226, -0.9945, -0.9781],<br>
[ 0.1318,  1.9036, -0.6613, -1.8101],<br>
[ 0.3844,  1.9908, -0.1160, -1.3563],<br>
[ 0.5801,  0.9606, -0.1840, -0.6442],<br>
[ 1.3811,  1.4375,  0.9490, -1.5605],<br>
[ 0.6690,  1.6736,  0.3756, -1.3233],<br>
[-0.4796,  0.7052, -0.7644,  0.4543],<br>
[ 0.0512,  0.9333,  1.0720, -0.9512],<br>
[-0.2501,  1.5006, -0.5616, -1.1430],<br>
[-0.8548,  3.5933, -0.1623, -2.5032],<br>
[ 0.5080,  2.9712, -0.9497, -2.4739],<br>
[ 0.6291,  1.5536,  0.4837, -2.5471],<br>
[ 2.3567,  2.0164,  0.6488, -3.2746],<br>
[ 1.1576,  1.3680, -0.0774, -1.6563],<br>
[ 0.1288,  0.7665, -0.1139,  0.3316],<br>
[ 0.3624,  2.1957,  0.8695, -0.9878],<br>
[ 0.0497,  1.1887, -0.4944, -1.7466]], device=‘cuda:0’,<br>
grad_fn=)<br>
labels :  tensor([[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[1, 0, 0, 0],<br>
[0, 1, 0, 0],<br>
[0, 1, 0, 0]], device=‘cuda:0’)</p>
<p>my loss func is CrossEntropyLoss()<br>
I got error “multi-target not supported at C:/cb/pytorch_1000000000000/work/aten/src\THCUNN/generic/ClassNLLCriterion.cu:18”</p>
<p>Help me bros… thanks</p>

ptrblck: <p><code>nn.CrossEntropyLoss</code> expects class indices, while your target is one-hot encoded.<br>
Use <code>target = torch.argmax(target, dim=1)</code> to create the expected target tensor.</p>

111394: <p>batch_size = 32</p>
<p>thanks, I used It<br>
target = torch.argmax(target, dim=1)<br>
=&gt;<br>
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,<br>
0, 0, 0, 0, 0, 0, 1, 1], device=‘cuda:0’)</p>
<p>but It is disappear class information<br>
[1, 0, 0, 0],  =&gt; class 1<br>
[0, 1, 0, 0],  =&gt; class 2<br>
[0, 0, 1, 0],  =&gt; class 3<br>
[0, 0, 0, 1],  =&gt; class 4</p>

ptrblck: <p>Your posted <code>labels</code> tensor only contains class0 and class1, so the output is expected.</p>

111394: <p>Thank you. I respect you.</p>