【问题标题】:Append two datasets (MNIST and SVHN)附加两个数据集(MNIST 和 SVHN)
【发布时间】:2021-10-17 01:25:57
【问题描述】:

我有两个数据集,MNIST 和 SVHN。 据了解,num。 MNIST 的测试样本为 1000 个,数量为 1000 个。 SVHN 的测试样本为 26032。 现在,我想将 SVHN 的测试集附加到 MNIST,因为 test_set_append[9999] 是 MNIST 的最后一个元素,而 test_set_append[10000] 是 SVHN 的第一个元素。 我已经尝试过使用 ConcatDataset:

class ConcatDataset(torch.utils.data.Dataset):
    def __init__(self, *datasets):
        self.datasets = datasets

    def __getitem__(self, i):
        return tuple(d[i] for d in self.datasets)

    def __len__(self):
        return min(len(d) for d in self.datasets)

但结果不是我想要的:

test_set = ConcatDataset(test_set_a, test_set_b)
test_set[1]
((tensor([[[0., 0., 0.,  ..., 0., 0., 0.],
           [0., 0., 0.,  ..., 0., 0., 0.],
           [0., 0., 0.,  ..., 0., 0., 0.],
           ...,
           [0., 0., 0.,  ..., 0., 0., 0.],
           [0., 0., 0.,  ..., 0., 0., 0.],
           [0., 0., 0.,  ..., 0., 0., 0.]]]), 2),
 (tensor([[[0.5451, 0.5451, 0.5451,  ..., 0.5176, 0.5216, 0.5255],
           [0.5725, 0.5686, 0.5686,  ..., 0.5373, 0.5333, 0.5333],
           [0.6039, 0.6000, 0.6000,  ..., 0.5686, 0.5569, 0.5490],
           ...,
           [0.6196, 0.6000, 0.5804,  ..., 0.3882, 0.4000, 0.4353],
           [0.5843, 0.5529, 0.5216,  ..., 0.3961, 0.4235, 0.4667],
           [0.5569, 0.5216, 0.4824,  ..., 0.4275, 0.4667, 0.5137]]]), 2))

【问题讨论】:

    标签: python neural-network pytorch conv-neural-network mnist


    【解决方案1】:

    我的自定义 ConcatDataset 返回一个包含两个数据集样本的元组。 解决办法是torch.utils.data.ConcatDataset([test_set_a, test_set_b])

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 2014-09-01
      • 2021-08-14
      • 2020-06-13
      相关资源
      最近更新 更多