Mulai sekarangMulai gratis

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!

Latihan ini merupakan bagian dari kursus

Intermediate Deep Learning with PyTorch

Lihat Kursus

Latihan interaktif langsung praktik

Cobalah latihan ini dengan melengkapi kode contoh ini.

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,
)
Edit dan Jalankan Kode