1、导入相关库
import torch
import torch.nn as nn #神经网络库
import torchvision #下载数据集,图像转换
from torchvision import transforms,datasets
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
2、载入数据
transform = transforms.Compose([ #定义transform
transforms.ToTensor(),#将图片由numpy类型转换为tensor类型,torch中数据类型为张量,tensor类型
transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))#归一化,0.5可自定义,范围在【-1,1】、
])
trainset = datasets.CIFAR10(root="D:/cifar10",train=True,download=True,transform=transform)#下载训练集,root表示存放路径,train为训练集,trandform表示对数据进行转换
testset = datasets.CIFAR10(root="D:/cifar10",train=False,download=True,transform=transform)#下载测试集,方法与训练集相
3、创建类
classes = {"plane","car","bird","cat","deer","dog","frog",&