[resolved] Validation Loss


How do you calculate the validation loss per iteration?

Say you’ve your train_loader and test_loader.

Normally for training per iteration to get the training loss, we do loss = criterion(outputs, labels where criterion = nn.CrossEntropyLoss() .

For validation per iteration,

            test_loss_iter = []
            for images, labels in test_loader:
                images = Variable(images.view(-1, 784).cuda())
                outputs = net(images)
                test_loss = criterion(outputs, labels)
            iteration_test_loss = np.mean(test_loss_iter)

But I get error AttributeError: 'torch.LongTensor' object has no attribute 'requires_grad'

Fixed it.

Set volatile=True for both images and targets.

1 Like