Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. # Train the model
  2. total_step = len(train_loader)
  3. for epoch in range(num_epochs):
  4. for i, (images, labels) in enumerate(train_loader):
  5. # Move tensors to the configured device
  6. images = images.to(device)
  7. labels = labels.to(device)
  8.  
  9. # Forward pass
  10. outputs = model(images)
  11. loss = loss_function(outputs, labels)
  12.  
  13. # Backward and optimize
  14. optimizer.zero_grad()
  15. loss.backward()
  16. optimizer.step()
  17.  
  18. if (i+1) % 100 == 0:
  19. print ('Epoch [{}/{}], Step [{}/{}], Loss: {:.4f}'
  20. .format(epoch+1, num_epochs, i+1, total_step, loss.item()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement