Train ConvNet using CIFAR10
Training an image classifier
We will do the following steps in order:
Load and normalizing the CIFAR10 training and test datasets using
torchvisionDefine a Convolutional Neural Network
Define a loss function
Train the network on the training data
Test the network on the test data
Data Loading
import torch
import torchvision
import torchvision.transforms as transformsThe output of torchvision datasets are PILImage images of range [0, 1]. We transform them to Tensors of normalized range [-1, 1].
Download General Dataset
Use Downloaded General Dataset
Change the option download=False, and set the path (root)where data is stored.
User Defined Dataset
Load and Show images(tensor, color)
Define Model
Define Loss function and Optimization
Train the network
Save model
Test the network
Show some ground truth of test data
Overall accuracy
Evaluate each class
numpy.squeeze() function is used when we want to remove single-dimensional entries from the shape of an array.
Exercise
Try increasing the width of your network (argument 2 of
the first
nn.Conv2d, and argument 1 of the secondnn.Conv2dthey need to be the same number), see what kind of speedup you get.
Build a MNIST Convnet
Last updated
Was this helpful?