Optimizers
It's time to explore the different optimizers that you can use for training your model.
A custom function called train_model(optimizer, net, num_epochs)
has been defined for you. It takes the optimizer, the model, and the number of epochs as inputs, runs the training loops, and prints the training loss at the end.
Let's use train_model()
to run a few short trainings with different optimizers and compare the results!
This exercise is part of the course
Intermediate Deep Learning with PyTorch
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import torch.optim as optim
net = Net()
# Define the SGD optimizer
optimizer = optim.____(net.parameters(), lr=0.001)
train_model(
optimizer=optimizer,
net=net,
num_epochs=10,
)