Aan de slagGa gratis aan de slag

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!

Deze oefening maakt deel uit van de cursus

Intermediate Deep Learning with PyTorch

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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,
)
Code bewerken en uitvoeren