Created
August 31, 2019 14:19
-
-
Save omarsar/994f85eda68b2c80951ec1cfddd48fab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## train the model | |
for epoch in range(num_epochs): | |
train_running_loss = 0.0 | |
train_acc = 0.0 | |
## commence training | |
model = model.train() | |
## training step | |
for i, (images, labels) in enumerate(trainloader): | |
images = images.to(device) | |
labels = labels.to(device) | |
## forward + backprop + loss | |
predictions = model(images) | |
loss = criterion(predictions, labels) | |
optimizer.zero_grad() | |
loss.backward() | |
## update model params | |
optimizer.step() | |
train_running_loss += loss.detach().item() | |
train_acc += get_accuracy(predictions, labels, BATCH_SIZE) | |
model.eval() | |
print('Epoch: %d | Loss: %.4f | Train Accuracy: %.2f' \ | |
%(epoch, train_running_loss / i, train_acc/i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment