1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Deep Learning with PyTorch

Exercise

Image classifier training loop

It's time to train the image classifier! You will use the Net you defined earlier and train it to distinguish between seven cloud types.

To define the loss and optimizer, you will need to use functions from torch.nn and torch.optim, imported for you as nn and optim, respectively. You don't need to change anything in the training loop itself: it's exactly like the ones you wrote before, with some additional logic to print the loss during training.

Instructions

100 XP
  • Define the model using your Net class with num_classes set to 7 and assign it to net.
  • Define the loss function as cross-entropy loss and assign it to criterion.
  • Define the optimizer as Adam, passing it the model's parameters and the learning rate of 0.001, and assign it to optimizer.
  • Start the training for-loop by iterating over training images and labels.