pytorch official tutorial training classifier code understanding
The novice's code is familiar, please point out if there is an error.
Generally, when you have to deal with image, text, audio or video data, you can use standard python packages to load the data into a numpy array. Then you can convert this array into a torch. * Tensor.
Especially for vision, we created a package called torchvision, which contains data loaders for common datasets, such as Imagenet, CIFAR10, MNIST, etc., and data converters for images, namely torchvision.datasets and torch .utils.data.DataLoader.
This provides great convenience and avoids writing boilerplate code.
In this tutorial, we will use the CIFAR10 dataset. It has classes: 'airplane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'. The image size in CIFAR-10 is 3x32x32, that is, a 3-channel color image with a size of 32x32 pixels.
Training image classifier
We will perform the following steps in order:
1. Use to load and standardize CIFAR10 training and test data set torchvision
2. Define the convolutional neural network
3. Define the loss function
4. Train the network on the training data
5. Test the network on the test data
Load and standardize CIFAR10 training and test data set torchvision
First show some pictures:
Define a convolutional neural network
Define the loss function
Train the network on the training data
Test the network on the test data
Code link:
https://github.com/Wenbin94/94/blob/master/lesson1.py