MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / ArrayDataset

Class ArrayDataset

imperative/python/megengine/data/dataset/meta_dataset.py:109–156  ·  view source on GitHub ↗

r"""ArrayDataset is a dataset for numpy array data. One or more numpy arrays are needed to initiate the dataset. And the dimensions represented sample number are expected to be the same. Args: Arrays(dataset and labels): the datas and labels to be returned iteratively. Ret

Source from the content-addressed store, hash-verified

107
108
109class ArrayDataset(Dataset):
110 r"""ArrayDataset is a dataset for numpy array data.
111
112 One or more numpy arrays are needed to initiate the dataset.
113 And the dimensions represented sample number are expected to be the same.
114
115 Args:
116 Arrays(dataset and labels): the datas and labels to be returned iteratively.
117
118 Returns:
119 Tuple: A set of raw data and corresponding label.
120
121
122 Examples:
123
124 .. code-block:: python
125
126 from megengine.data.dataset import ArrayDataset
127 from megengine.data.dataloader import DataLoader
128 from megengine.data.sampler import SequentialSampler
129
130 rand_data = np.random.randint(0, 255, size=(sample_num, 1, 32, 32), dtype=np.uint8)
131 label = np.random.randint(0, 10, size=(sample_num,), dtype=int)
132 dataset = ArrayDataset(rand_data, label)
133 seque_sampler = SequentialSampler(dataset, batch_size=2)
134
135 dataloader = DataLoader(
136 dataset,
137 sampler = seque_sampler,
138 num_workers=3,
139 )
140
141 for step, data in enumerate(dataloader):
142 print(data)
143
144 """
145
146 def __init__(self, *arrays):
147 super().__init__()
148 if not all(len(arrays[0]) == len(array) for array in arrays):
149 raise ValueError("lengths of input arrays are inconsistent")
150 self.arrays = arrays
151
152 def __getitem__(self, index: int) -> Tuple:
153 return tuple(array[index] for array in self.arrays)
154
155 def __len__(self) -> int:
156 return len(self.arrays[0])
157
158
159class ConcatDataset(Dataset):

Callers 13

test_array_datasetFunction · 0.90
test_concat_datasetFunction · 0.90
init_datasetFunction · 0.90
init_datasetFunction · 0.90
test_init_datasetFunction · 0.90
test_sequential_samplerFunction · 0.90
test_RandomSamplerFunction · 0.90
test_InfiniteSamplerFunction · 0.90
test_random_sampler_seedFunction · 0.90
test_ReplacementSamplerFunction · 0.90

Calls

no outgoing calls

Tested by 13

test_array_datasetFunction · 0.72
test_concat_datasetFunction · 0.72
init_datasetFunction · 0.72
init_datasetFunction · 0.72
test_init_datasetFunction · 0.72
test_sequential_samplerFunction · 0.72
test_RandomSamplerFunction · 0.72
test_InfiniteSamplerFunction · 0.72
test_random_sampler_seedFunction · 0.72
test_ReplacementSamplerFunction · 0.72