datalloader函数,并清除iter函数,但next()函数导致错误

时间:2019-04-01 18:11:22

标签: python deep-learning pytorch

在pytorch中使用了datalloader函数,并且清除了iter函数,但是next()函数导致错误。如果您知道解决方案或原因,请帮助我。

我已经更改了批量大小。

import torch
import torchvision
import torchvision.transforms as transforms
from torchvision.datasets import ImageFolder

transform = transforms.Compose([transforms.Resize(224,224),
                                transforms.ToTensor(),
                                transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))])

train = ImageFolder('/home/minseok/study/dog_cat/train',transform)
valid = ImageFolder('/home/minseok/study/dog_cat/valid',transform)

train_loader = torch.utils.data.DataLoader(train,batch_size=256,num_workers=8,shuffle=True)
valid_loader = torch.utils.data.DataLoader(valid,batch_size=2,num_workers=1,shuffle=True)

dataiter = iter(valid_loader)  #It's safe up to here
images, labels = dataiter.next() # error

很抱歉我的英语解释不好,因为它不是英语。

1 个答案:

答案 0 :(得分:0)

您尝试过这个吗?

images, labels = next(dataiter)