1 回答
TA贡献1785条经验 获得超4个赞
您应该能够很好地循环访问 Subset,因为它实现了从源代码中看到的方法:__getitem__
class Subset(Dataset):
r"""
Subset of a dataset at specified indices.
Arguments:
dataset (Dataset): The whole Dataset
indices (sequence): Indices in the whole set selected for subset
"""
def __init__(self, dataset, indices):
self.dataset = dataset
self.indices = indices
def __getitem__(self, idx):
return self.dataset[self.indices[idx]]
def __len__(self):
return len(self.indices)
因此,以下方法应该有效:
for image, label in train_dataset:
print(image, label)
或者,您可以从子集创建数据加载器:
train_dataloader = DataLoader(train_dataset, batch_size, shuffle)
for images, labels in train_dataloader:
print(images, labels)
与 相同。validation_dataset
添加回答
举报