Created
July 25, 2019 01:15
-
-
Save Hanrui-Wang/124514c1b4babb7f12ddcfd740a6957b to your computer and use it in GitHub Desktop.
how to model eval and torch no_grad in the test set
This file contains hidden or 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
# Test the model | |
model.eval() # eval mode (batchnorm uses moving mean/variance instead of mini-batch mean/variance) | |
with torch.no_grad(): | |
correct = 0 | |
total = 0 | |
for images, labels in test_loader: | |
images = images.to(device) | |
labels = labels.to(device) | |
outputs = model(images) | |
_, predicted = torch.max(outputs.data, 1) | |
total += labels.size(0) | |
correct += (predicted == labels).sum().item() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment