我的DataLoader在每个时期都会给我返回相同的图像。我的模型每次只查看相同的单个图像(索引为'0') (批次大小是1...although,不同的批次大小不会发生任何变化)。
以下是我的数据集,精简到重要的部分:
class MyDataset(Dataset):
def __init__(self, path, loader=pil_loader):
self.path = path
self.images = os.listdir(path)
def __getitem__(self, index):
image = self.images[index]
. . .下面是DataSet:
train_ds = MyDataset('/data')这是我的采样器:
train_sampler = RandomSampler(train_ds)下面是我的DataLoader:
train_dl = DataLoader(train_ds, batch_size=1, sampler=train_sampler)我不确定为什么在训练期间,它每次都给我返回相同的图像。
我的RandomSampler设置不完整吗?或者可能是我写错了__getitem__?我想不出来。
发布于 2018-05-03 03:42:46
啊哈。好吧,如果有人在这里遇到了同样的问题,我知道是什么了,也许这会有所帮助。
我对__len__的定义是错误的。
我猜随机采样器取决于您如何设置长度方法。
我的被临时模拟为
def __len__(self):
return len(0)而不是一些真实的东西,比如:
def __len__(self):
return len(self.images)https://stackoverflow.com/questions/50124712
复制相似问题