Skip to content

Instantly share code, notes, and snippets.

@johnolafenwa
Last active May 8, 2018 19:06
Show Gist options
  • Save johnolafenwa/eae9e79aeb3ab7647168aed9cdd65c07 to your computer and use it in GitHub Desktop.
Save johnolafenwa/eae9e79aeb3ab7647168aed9cdd65c07 to your computer and use it in GitHub Desktop.
def test():
model.eval()
test_acc = 0.0
for i, (images, labels) in enumerate(test_loader):
if cuda_avail:
images = Variable(images.cuda())
labels = Variable(labels.cuda())
# Predict classes using images from the test set
outputs = model(images)
_, prediction = torch.max(outputs.data, 1)
test_acc += torch.sum(prediction == labels.data)
# Compute the average acc and loss over all 10000 test images
test_acc = test_acc / 10000
return test_acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment