Tensorboard graphs

This include loss and accuracy graphs for both training and validation loops
mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
2
Indexable
Never
#CODE FOR LOSS & ACCURACY GRAPHS USING TENSORBOARD

#import statements
from torch.utils.tensorboard import SummaryWriter


tb  = SummaryWriter('runs/ich_detection_experiment_1')


#TRAINING---
#We are gonna do same as we did inside validation

#Insert below code before loop starts
new = []
train_pred = np.zeros((len(train_dataset) * n_classes, 1))

#Insert below code after train loss calculation

#create a variable "tr_correct" just like "tr_loss"

new.append(torch.sigmoid(pred).detach().cpu())
new1=torch.sigmoid(pred).detach().cpu()>=0.5

tr_correct += torch.sum(new1 == labels)

#After training loss print statement

tb.add_scalar("Training Loss", tr_loss, epoch)
tb.add_scalar("Training Accuracy", tr_correct/ len(train_dataset), epoch)

#FINISHED TRAINING---

#VALIDATION---
#Again create a variable "tr_correct" just like "tr_loss"

tr_correct += torch.sum(new1 == labels)

#After training loss print statement

tb.add_scalar("Validation Loss", tr_loss, epoch)
tb.add_scalar("Validation Accuracy", tr_correct/ len(validation_dataset), epoch)

#END---