Writing the evaluation loop
In this exercise, you will write an evaluation loop to compute validation loss. The evaluation loop follows a similar structure to the training loop but without gradient calculations or weight updates.
model
, validationloader
, and loss function criterion
have already been defined to handle predictions, data loading, and loss calculation.
This exercise is part of the course
Introduction to Deep Learning with PyTorch
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Set the model to evaluation mode
____
validation_loss = 0.0
with torch.no_grad():
for features, labels in validationloader:
outputs = model(features)
loss = criterion(outputs, labels)
# Sum the current loss to the validation_loss variable
validation_loss += ____