Created
January 27, 2020 13:43
-
-
Save aravindpai/4569c9c8daa67283fcb6be948ae22435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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