以下就是完整的神经网络模型验证套路,我们拿到的数据集是CIFAR10,CIFAR-10数据集由10个类的60000个32x32彩色图像组成,每个类有6000个图像。有50000个训练图像和10000个测试图像。它能够将图像进行10分类。我们训练好我们的模型之后,那么模型已经保存好了,我们就要拿这个模型来验证我们的分类效果如何,下面就是完整的神经网络模型验证套路:
# 姓 名:杨雅静
# 开发时间:2021/11/15 9:33
import torch
import torchvision
from PIL import Image
from torch import nn
from torch.nn import Conv2d, MaxPool2d, Flatten, Linear
image_path="F:\learn-pytorch\image\miao.png"
image = Image.open(image_path)
print(image)
transform=torchvision.transforms.Compose([torchvision.transforms.Resize((32,32)),torchvision.transforms.ToTensor()])
image=transform(image)
print(image.shape)
class net_work(nn.Module): #这是搭建的神经网络模型,可写可不写,删掉也可以
def __init__(self):
super(net_work, self).__init__()
self.model = nn.Sequential(
Conv2d(3, 32, 5, padding=2),
MaxPool2d(2),
Conv2d(32, 32, 5, padding=