Skip to content

Instantly share code, notes, and snippets.

@omarsar
Created August 19, 2018 03:13
Show Gist options
  • Save omarsar/30b871caae9fcb49e031c2508ec4fe40 to your computer and use it in GitHub Desktop.
Save omarsar/30b871caae9fcb49e031c2508ec4fe40 to your computer and use it in GitHub Desktop.
import torch.optim as optim
# Device
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# Model instance
model = ImageRNN(BATCH_SIZE, N_STEPS, N_INPUTS, N_NEURONS, N_OUTPUTS)
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)
def get_accuracy(logit, target, batch_size):
''' Obtain accuracy for training round '''
corrects = (torch.max(logit, 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