Plotting loss and accuracy

I want to use lists to record my accuracy and loss in order to plot them at the end. But when I add the lines for tracking the loss (I do it for training and testing) my accuracy gets worse.
This is essentially how my code looks:

train_loss_history = []
train_loss_history = []

for epoch in range(epoch_resume, opt.max_epochs):
   for i, data in enumerate(trainloader, 0):
      train_loss     += imgs.size(0)*criterion(logits, labels).data
   train_loss     /= len(trainset)

I can’t imagine how appending the values to a list can affect the training. Do you have any idea what I am missing?

For fully debug this issue I think I need to run the code. But first thing I would change is

Hi, thank you for your answer! Unfortunately using .item() did not work, but I tried to work around it and now use tensorboard to plot my loss and accuracy. Now it works fine:)

1 Like