Created
September 29, 2021 02:17
-
-
Save napoler/4992697fce159c90aa0af28afe01d066 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CASE 1: A single test dataset | |
def test_step(self, batch, batch_idx): | |
x, y = batch | |
# implement your own | |
out = self(x) | |
loss = self.loss(out, y) | |
# log 6 example images | |
# or generated text... or whatever | |
sample_imgs = x[:6] | |
grid = torchvision.utils.make_grid(sample_imgs) | |
self.logger.experiment.add_image('example_images', grid, 0) | |
# calculate acc | |
labels_hat = torch.argmax(out, dim=1) | |
test_acc = torch.sum(y == labels_hat).item() / (len(y) * 1.0) | |
# log the outputs! | |
self.log_dict({'test_loss': loss, 'test_acc': test_acc}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment