From the course: PyTorch Essential Training: Working with Images

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Setting up the training loop

Setting up the training loop

- [Instructor] Let's dive into understanding the function for training our model. First, we define a variable called since that we will use to store the total time it takes to complete the training process. We set it to the current time by using the time.time function. Let's create the backup of the model starting state and call it best_model_vts. We'll do that by calling the two functions, copy.deepcopy and model_state_dict. So we can return a dictionary containing all the parameters of the model, meaning weights and biases for each layer at the exact moment. We are doing this to save the model when it's performing the best. Next, we'll also create a variable called best_accuracy so we can track the best validation accuracy during the training. Let's initialize it to zero. After each epoch, we'll update this value with the best accuracy achieved with the model during the training process. Let's understand the training loop. As you can see, we have three, four loops. Training happens…

Contents