Skip to content
Advertisement

Calculate the accuracy every epoch in PyTorch

I am working on a Neural Network problem, to classify data as 1 or 0. I am using Binary cross entropy loss to do this. The loss is fine, however, the accuracy is very low and isn’t improving. I am assuming I did a mistake in the accuracy calculation. After every epoch, I am calculating the correct predictions after thresholding the output, and dividing that number by the total number of the dataset. Is there any thing wrong I did in the accuracy calculation? And why isn’t it improving, but getting more worse? This is my code:

JavaScript

And this is the strange output I get:

JavaScript

Advertisement

Answer

Is x the entire input dataset? If so, you might be dividing by the size of the entire input dataset in correct/x.shape[0] (as opposed to the size of the mini-batch). Try changing this to correct/output.shape[0]

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement