Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. for e in range(epoch):
  2. loss_epoch = 0
  3. ################################################################################
  4. # TODO: #
  5. # Loop through the dataloader and train your model with nn.BCELoss. #
  6. ################################################################################
  7. for x, y in train_loader:
  8. optim.zero_grad()
  9. y_pred = model(x)
  10. # Compute and print loss
  11. loss = criterion(y_pred, y.float().unsqueeze(1))
  12. loss.backward()
  13. optim.step()
  14. loss_epoch += loss.item()
  15. ################################################################################
  16. # END OF YOUR CODE #
  17. ################################################################################
  18. if e % print_every == 0:
  19. y_pred = (model(X_train.float()) > 0.5)
  20. train_acc = get_acc(y_pred, y_train)
  21. y_val_pred = (model(X_val.float()) > 0.5)
  22. val_acc = get_acc(y_val_pred, y_val)
  23. print(f'Epcoh {e}: {loss_epoch}, Training accuracy: {train_acc}, Validation accuracy: {val_acc}')
  24. return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement