2 00:00:04,000 --> 00:00:06,633 Torch-Vision Models are popular models that have been developed by experts, we can use these models to help better classify our own images. We will focus on how to use pre-trained models, these models have been trained by experts. We simply train the output layer of these models to classify our own data set. Let's see how to use pre-trained models, most of these models use color images. We will use the Resnet 18 a type of residual networks that uses skip connections, We will not concern ourselves with the model details but the model we have used has been expertly trained and the parameters will be optimized with lots of data. The model uses skip connections, although we will not cover this we will add an arrow to signify this. We are concerned with the last hidden layer as well as the output layer We can train the model to classify a set of images all we need is a training set. We will need the following libraries. You should load the resnet18 model, setting the parameter pretrained to True, this means the model has been trained before. We have to normalize the image channels, for resnet 28 we have the following values, We then apply compose to the following transforms: “Resize”, To “Tensor” and “Normalize”. We will apply each of the transforms. Different pretrained models will have different values. You should create a dataset object for your data that will have training and testing data. You will simply replace the output layer of the pretrained model with your own output layer. This will allow you to use the output of the pretrained model as input to your own output layer. As you will only change the output layer of the pretrained model, you will set the parameter requires grad equal to false. You will replace the output layer with your own fully connected layer, as the last hidden layer has 512 neurons you will have 512 inputs. For this example, we will have 7 classes as a result we will have 7 outputs one for each class. You will create a train loader and testing loader object, with the batch size 15 and 10 respectively You will create a cross entropy criterion function, you create an optimizer object, the optimizer will only use parameters where the grad attribute is set to true. You will create a list for the training loss and validation accuracy, you will also have to determine the number of epochs in this case 20 plus several other parameters. The training process is similar, the main difference is, we will set the model to train for training. We also set the model to evaluate to make a prediction. Try to pretrain your own model. 30 00:02:49,733 --> 00:02:50,733