Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Created January 27, 2020 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aravindpai/4569c9c8daa67283fcb6be948ae22435 to your computer and use it in GitHub Desktop.
Save aravindpai/4569c9c8daa67283fcb6be948ae22435 to your computer and use it in GitHub Desktop.
import torch.optim as optim
#define optimizer and loss
optimizer = optim.Adam(model.parameters())
criterion = nn.BCELoss()
#define metric
def binary_accuracy(preds, y):
#round predictions to the closest integer
rounded_preds = torch.round(preds)
correct = (rounded_preds == y).float()
acc = correct.sum() / len(correct)
return acc
#push to cuda if available
model = model.to(device)
criterion = criterion.to(device)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment