Created
December 30, 2021 21:08
-
-
Save GitHubEmploy/a870195a4c7318ee64eb406b26fc706a 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
# Train the model | |
total_step = len(train_loader) | |
for epoch in range(num_epochs): | |
for i, (images, labels) in enumerate(train_loader): | |
# Move tensors to the configured device | |
images = images.to(device) | |
labels = labels.to(device) | |
# Forward pass | |
outputs = model(images) | |
loss = loss_function(outputs, labels) | |
# Backward and optimize | |
optimizer.zero_grad() | |
loss.backward() | |
optimizer.step() | |
if (i+1) % 100 == 0: | |
print ('Epoch [{}/{}], Step [{}/{}], Loss: {:.4f}' | |
.format(epoch+1, num_epochs, i+1, total_step, loss.item())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment