Created
August 24, 2019 18:00
-
-
Save omarsar/011ac9c51eb5f2e96a19919349327afc 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
for epoch in range(num_epochs): | |
train_running_loss = 0.0 | |
train_acc = 0.0 | |
model = model.train() | |
## training step | |
for i, (images, labels) in enumerate(trainloader): | |
images = images.to(device) | |
labels = labels.to(device) | |
## forward + backprop + loss | |
logits = model(images) | |
loss = criterion(logits, labels) | |
optimizer.zero_grad() | |
loss.backward() | |
## update model params | |
optimizer.step() | |
train_running_loss += loss.detach().item() | |
train_acc += get_accuracy(logits, 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