batch_dataset
BatchDataset
¶
Bases: FEDataset
BatchDataset extracts a list (batch) of data from a single dataset or multiple datasets.
This dataset helps to enable several use-cases: 1. Creating an unpaired dataset from two or more completely disjoint (no common keys) datasets.
ds1 = fe.dataset.DirDataset(...) # {"a": <32x32>}
ds2 = fe.dataset.DirDataset(...) # {"b": <28x28>}
unpaired_ds = fe.dataset.BatchDataset(datasets=[ds1, ds2], num_samples=[4, 4])
# {"a": <4x32x32>, "b": <4x28x28>}
class1_ds = fe.dataset.DirDataset(...) # {"x": <32x32>, "y": <>}
class2_ds = fe.dataset.DirDataset(...) # {"x": <32x32>, "y": <>}
ds = fe.dataset.BatchDataset(datasets=[ds1, ds2], num_samples=[3, 5])
# {"x": <8x32x32>, "y": <8>} (3 of the samples are from class1_ds, 5 of the samples from class2_ds)
class1_ds = fe.dataset.DirDataset(...) # {"x": <32x32>, "y": <>}
class2_ds = fe.dataset.DirDataset(...) # {"x": <32x32>, "y": <>}
ds = fe.dataset.BatchDataset(datasets=[ds1, ds2], num_samples=8, probability=[0.7, 0.3])
# {"x": <8x32x32>, "y": <8>} (~70% of the samples are from class1_ds, ~30% of the samples from class2_ds)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datasets |
Union[FEDataset, Iterable[FEDataset]]
|
The dataset(s) to use for batch sampling. While these should be FEDatasets, pytorch datasets will technically also work. If you use them, however, you will lose the .split() and .summary() methods. |
required |
num_samples |
Union[int, Iterable[int]]
|
Number of samples to draw from the |
required |
probability |
Optional[Iterable[float]]
|
Probability to draw from each dataset. Only allowed if |
None
|
Source code in fastestimator\fastestimator\dataset\batch_dataset.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
reset_index_maps
¶
Rearrange the index maps of this BatchDataset.
This method is invoked every epoch by OpDataset which allows each epoch to have different random pairings of the basis datasets.
Source code in fastestimator\fastestimator\dataset\batch_dataset.py
split
¶
Split this dataset into multiple smaller datasets.
This function enables several types of splitting: 1. Splitting by fractions.
ds = fe.dataset.FEDataset(...) # len(ds) == 1000
ds2 = ds.split(0.1) # len(ds) == 900, len(ds2) == 100
ds3, ds4 = ds.split(0.1, 0.2) # len(ds) == 630, len(ds3) == 90, len(ds4) == 180
ds = fe.dataset.FEDataset(...) # len(ds) == 1000
ds2 = ds.split(100) # len(ds) == 900, len(ds2) == 100
ds3, ds4 = ds.split(90, 180) # len(ds) == 630, len(ds3) == 90, len(ds4) == 180
ds = fe.dataset.FEDataset(...) # len(ds) == 1000
ds2 = ds.split([87,2,3,100,121,158]) # len(ds) == 994, len(ds2) == 6
ds3 = ds.split(range(100)) # len(ds) == 894, len(ds3) == 100
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*fractions |
Union[float, int, Iterable[int]]
|
Floating point values will be interpreted as percentages, integers as an absolute number of datapoints, and an iterable of integers as the exact indices of the data that should be removed in order to create the new dataset. |
()
|
Returns:
Type | Description |
---|---|
Union[BatchDataset, List[BatchDataset]]
|
One or more new datasets which are created by removing elements from the current dataset. The number of |
Union[BatchDataset, List[BatchDataset]]
|
datasets returned will be equal to the number of |
Union[BatchDataset, List[BatchDataset]]
|
then the return will be a single dataset rather than a list of datasets. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the user created this dataset using one or more non-FEDataset inputs. |
Source code in fastestimator\fastestimator\dataset\batch_dataset.py
summary
¶
Generate a summary representation of this dataset.
Returns:
Type | Description |
---|---|
DatasetSummary
|
A summary representation of this dataset. |