Created
September 7, 2020 15:19
-
-
Save MLWhiz/49d0e07e879568b0656a45f552a665b7 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
num_epochs = 5 | |
for epoch in range(num_epochs): | |
model.train() | |
for x_batch,y_batch in train_dataloader: | |
if train_on_gpu: | |
x_batch,y_batch = x_batch.cuda(), y_batch.cuda() | |
optimizer.zero_grad() | |
pred = model(x_batch) | |
loss = loss_criterion(pred, y_batch) | |
loss.backward() | |
optimizer.step() | |
model.eval() | |
for x_batch,y_batch in valid_dataloader: | |
if train_on_gpu: | |
x_batch,y_batch = x_batch.cuda(), y_batch.cuda() | |
pred = model(x_batch) | |
val_loss = loss_criterion(pred, y_batch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment