资源简介
pytorch编写的cifar10数据集分类程序,利用LeNet进行分类
代码片段和文件信息
# -*- coding:utf-8 -*-
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
transform=transforms.Compose([transforms.ToTensor()transforms.Normalize((0.50.50.5)(0.50.50.5))])
trainset=torchvision.datasets.CIFAR10(root=‘./data‘train=Truedownload=Falsetransform=transform)
trainloader=torch.utils.data.DataLoader(trainsetbatch_size=5shuffle=Truenum_workers=2)
testset=torchvision.datasets.CIFAR10(root=‘./data‘train=Falsedownload=Falsetransform=transform)
testloader=torch.utils.data.DataLoader(testsetbatch_size=5shuffle=Falsenum_workers=2)
classes=(‘plane‘‘automobile‘‘bird‘‘cat‘‘deer‘‘dog‘‘frog‘‘horse‘‘ship‘‘truck‘)
# import matplotlib.pyplot as plt
# import numpy as np
# def imshow(img):
# img=img/2+0.5
# nimg=img.num
评论
共有 条评论