"Loss" and "accuracy" are weird

username: 111394
cooked: <p>running_loss and Accuracy is weird.<br>
Is there any expected problem?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/5/75dfa1e882e4a61b7c759a48802bf3a8bebc9744.png" data-download-href="https://discuss.pytorch.org/uploads/default/75dfa1e882e4a61b7c759a48802bf3a8bebc9744" title="123123"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/5/75dfa1e882e4a61b7c759a48802bf3a8bebc9744_2_690x280.png" alt="123123" data-base62-sha1="gOKZElbK5z5K0WnscqkvcK0i7cg" width="690" height="280" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/5/75dfa1e882e4a61b7c759a48802bf3a8bebc9744_2_690x280.png, https://discuss.pytorch.org/uploads/default/optimized/3X/7/5/75dfa1e882e4a61b7c759a48802bf3a8bebc9744_2_1035x420.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/7/5/75dfa1e882e4a61b7c759a48802bf3a8bebc9744_2_1380x560.png 2x" data-dominant-color="F5F8FB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">123123</span><span class="informations">1825×743 48.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: ptrblck
cooked: <p>What do you mean by “expected problem”?</p>
<p>Could you explain the x-axis in both plots? Are you printing some iterations or epochs?<br>
Also, what is your current use case, i.e. if it’s a classification use case what is the number of classes, are the classes balanced etc?</p>
<p>Based on the accuracy plot it also seems you are plotting two (or multiple) values for the same step?<br>
Is this on purpose?</p>

username: 111394
cooked: <p>thanks for Answer</p>
<p>plot1 loss_tracker<br>
x : Accumulation batchs number<br>
y: running loss</p>
<p>plot2 Accuracy<br>
x : Accumulation epoch number<br>
y:  accuracy</p>
<p>four-class classification,<br>
Output : tensor([[-1867.3853, -5551.1318, -4450.6240, 11866.9102],<br>
[-2225.3528, -5707.1665, -2959.6877, 10890.8711],<br>
[-2529.1191, -5777.2607, -4512.0718, 12815.6875],<br>
[-2559.4792, -6071.3545, -3919.7209, 12546.3398]], device=‘cuda:0’)</p>
<p>Target : tensor([3, 3, 3, 3], device=‘cuda:0’)<br>
Loss: 0.0</p>
<p>I often get a loss of zero in the course of learning.</p>

username: ptrblck
cooked: <p>Thanks for the update.<br>
Could you check, if your model is only predicting <code>class3</code> and check, if this would explain this shaky loss curve?</p>
<p>Also, the second plot still seems to plot some outputs for the same x-value, so you should double check the code logic for the plotting.</p>

username: 111394
cooked: <h2>Output : tensor([[ -28.4967,   14.9120,  146.2759, -132.4498],<br>
[   3.0310,   41.4412,   18.8934,  -62.9328],<br>
[  75.7614,  -30.5392, -390.3096,  344.8382],<br>
[  70.0653,  -71.1584, -411.3787,  412.4350]], device=‘cuda:0’)</h2>
<p>Target : tensor([2, 2, 3, 3], device=‘cuda:0’)</p>
<p>I think classify other classes as well.</p>
<p>[second plot]<br>
def acc_check(net, test_set, epoch, save=1):<br>
net.eval()<br>
correct = 0<br>
total = 0<br>
with torch.no_grad():<br>
for data in test_set:<br>
inputs, labels = data<br>
inputs = inputs.to(device)<br>
labels = torch.argmax(labels, dim=1)<br>
labels = labels.to(device)<br>
outputs = net(inputs.permute(0,4,1,2,3))</p>
<pre><code>        _, predicted = torch.max(outputs.data, 1)
        #print("labels : ",labels)
        #print("prediced :" ,predicted)
        total += labels.size(0)
        correct += (predicted == labels).sum().item()

acc = (100 * correct / total)
print('Accuracy of the network on the 10000 test images: %d %%' % acc)
if epoch%50==0:
    torch.save(net, "D:/data/3dcnn_weights/basic128_epoch_{}_acc_{}.pth".format(epoch, int(acc)))
    pass
return acc
</code></pre>
<p>acc = acc_check(model_ft, test_loader, epoch, save=1)<br>
value_tracker(acc_plt, torch.Tensor([acc]), torch.Tensor([epoch]))</p>
<p>thanks</p>