How to plot train and validation accuracy graph?

Easy way to plot train and val accuracy
train loss and val loss graph.

1 Like

One simple way to plot your losses after the training would be using matplotlib:

import matplotlib.pyplot as plt

val_losses = []
train_losses = []
training loop
train_losses.append(loss_train.item())

testing
val_losses.append(loss_val.item())

plt.figure(figsize=(10,5))
plt.title("Training and Validation Loss")
plt.plot(val_losses,label="val")
plt.plot(train_losses,label="train")
plt.xlabel("iterations")
plt.ylabel("Loss")
plt.legend()
plt.show()

The more elegant way, which lets you check your progress during training as well is tensorboard:

from torch.utils.tensorboard import SummaryWriter

# Writer will output to ./runs/ directory by default
writer = SummaryWriter(logdir)

training loop
train_loss += loss_train.item()
writer.add_scalar('Loss/train', training_loss, global_step)

testing
val_loss += loss_val.item()
writer.add_scalar('Loss/val', val_loss, global_step)

writer.close()

Accuracy works the same

thank u for your reply