Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 =
criterion =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment