我试图用torchvision的mnist数据集制作ai,并用pytorch制作ai,但当我键入一些对数据进行洗牌的代码并运行时,它会说:
trainset = torch.utils.data.Dataloader(train, batch_size=10, shuffle=True)
AttributeError: module 'torch.utils.data' has no attribute 'Dataloader'
我尝试了difrent方法,但仍然不起作用,它说:
trainset = torch.autograd.Variable.DataLoader(train, batch_size=10, shuffle=True)
AttributeError: type object 'Variable' has no attribute 'DataLoader'
我使用的代码是:
import torch
import numpy as np
import torchvision
from torchvision import transforms, datasets
train = datasets.MNIST("", train=True, download=True,
transform = transforms.Compose([transforms.ToTensor()]))
test = datasets.MNIST("", train=False, download=True,
transform = transforms.Compose([transforms.ToTensor()]))
trainset = torch.utils.data.Dataloader(train, batch_size=10, shuffle=True)
testset = torch.utils.data.Dataloader(test, batch_size=10, shuffle=True)
for data in trainset:
print(data)
break
此代码中的eror:
trainset = torch.utils.data.Dataloader(train, batch_size=10, shuffle=True)
AttributeError: module 'torch.utils.data' has no attribute 'Dataloader'
我尝试了一个新版本,但仍然不起作用:
import torch
import numpy as np
import torchvision
from torchvision import transforms, datasets
train = datasets.MNIST("", train=True, download=True,
transform = transforms.Compose([transforms.ToTensor()]))
test = datasets.MNIST("", train=False, download=True,
transform = transforms.Compose([transforms.ToTensor()])
trainset = torch.autograd.Variable.DataLoader(train, batch_size=10, shuffle=True)
testset = torch.autograd.Variable.DataLoader(test, batch_size=10, shuffle=True)
for data in trainset:
print(data)
break
此代码中的eror:
trainset = torch.autograd.Variable.DataLoader(train, batch_size=10, shuffle=True)
AttributeError: type object 'Variable' has no attribute 'DataLoader'
我仍然很困惑为什么它不起作用,我一直在遵循一个教程,但它不起作用
您有一个简单的打字错误:} (大写{})
Dataloader
->^{尝试:
相关问题 更多 >
编程相关推荐