pytorch official tutorial training classifier code understanding

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.
Insert picture description here

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

Insert picture description here
Insert picture description here
First show some pictures:
Insert picture description here

Define a convolutional neural network

Insert picture description here
Insert picture description here
Insert picture description here

Define the loss function


Insert picture description here

Train the network on the training data

Insert picture description here

Test the network on the test data

Insert picture description here
Insert picture description here
Insert picture description here
Code link:
https://github.com/Wenbin94/94/blob/master/lesson1.py

Published 6 original articles · received 1 · views 468

Guess you like

Origin blog.csdn.net/weixin_43590151/article/details/90203761