赞
踩
- #配置库
- import torch
- from torch import nn,optim
- import torch.nn.functional as F
- from torch.autograd import Variable
- from torch.utils.data import DataLoader
- from torchvision import transforms
- from torchvision import datasets
- import matplotlib.pyplot as plt
- import numpy as np
- import torch.nn as nn
- import torch.nn.functional as F
- import torch.optim as optim # 优化器
- import torchvision
- me v 15563370935
- #配置参数
- torch.manual_seed(1)#设置随机数种子,确保结果可重复
- # batch_size=128 #批处理大小
- learning_rate=0.001 #学习率
- num_epoches=10 #训练次数
-
-
- #加载CIFAR-10数据
- #(ToTensor():把一个PIL.Image转换成Tensor,Normalize():标准化,即减均值,除以标准差)
- transform=transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
- #训练集
- trainset=datasets.CIFAR10(root='./data', train=True,download=True, transform=transform)
- #测试集
- testset=datasets.CIFAR10(root='./data', train=False,download=True, tra
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。