Skip to content

Instantly share code, notes, and snippets.

@vsay01
Created January 22, 2020 12:57
Show Gist options
  • Save vsay01/31fd0bd7a49b98bbb823a0249b38c37b to your computer and use it in GitHub Desktop.
Save vsay01/31fd0bd7a49b98bbb823a0249b38c37b to your computer and use it in GitHub Desktop.
Make prediction
test_acc = 0.0
for samples, labels in loaders['test']:
with torch.no_grad():
samples, labels = samples.cuda(), labels.cuda()
output = trained_model(samples)
# calculate accuracy
pred = torch.argmax(output, dim=1)
correct = pred.eq(labels)
test_acc += torch.mean(correct.float())
print('Accuracy of the network on {} test images: {}%'.format(len(testset), round(test_acc.item()*100.0/len(loaders['test']), 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment