Skip to content

Instantly share code, notes, and snippets.

@omarsar
Created August 31, 2019 14:18
Show Gist options
  • Save omarsar/e23fafb13cabe911c45c5dc1fe2be371 to your computer and use it in GitHub Desktop.
Save omarsar/e23fafb13cabe911c45c5dc1fe2be371 to your computer and use it in GitHub Desktop.
## utility function to compute accuracy
def get_accuracy(output, target, batch_size):
''' Obtain accuracy for training round '''
corrects = (torch.max(output, 1)[1].view(target.size()).data == target.data).sum()
accuracy = 100.0 * corrects/batch_size
return accuracy.item()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment