ConcatDataset

class ConcatDataset(datasets)[源代码]

ConcatDataset is a concatenation of multiple datasets.

This dataset is used for assembleing multiple map-style datasets.

参数

datasets (list of Dataset) – list of datasets to be composed.

返回

A Dataset which composes fields of multiple datasets.

返回类型

Dataset

实际案例

from megengine.data.dataset import ArrayDataset, ConcatDataset

data1 = np.random.randint(0, 255, size=(2, 1, 32, 32), dtype=np.uint8)
data2 = np.random.randint(0, 255, size=(2, 1, 32, 32), dtype=np.uint8)
label = np.random.randint(0, 10, size=(2,), dtype=int)
labe2 = np.random.randint(0, 10, size=(2,), dtype=int)
dataset1 = ArrayDataset(data1, label1)
dataset2 = ArrayDataset(data2, label2)
dataset = ConcatDataset([dataset1, dataset2])
seque_sampler = SequentialSampler(dataset, batch_size=2)

dataloader = DataLoader(
    dataset,
    sampler = seque_sampler,
    num_workers=3,
)

for step, data in enumerate(dataloader):
    print(data)