interleave_dataset
InterleaveDataset
¶
Bases: FEDataset
A Dataset class that can allow for a step-wise interleaving of multiple datasets.
This will be useful for training multi-task models when we vary dataset used on a per-step basis.
For example, given dataset ds1
, and ds2
, if we want to vary dataset between each step, the following 3 will
produce the same behavior: step0 getting samples from ds1, step1 getting samples from ds2, and repeat.
dataset = InterleaveDataset(datasets=[ds1, ds2])
dataset = InterleaveDataset(datasets=[ds1, ds2], pattern=[0, 1])
dataset = InterleaveDataset(datasets={"a": ds1, "b": ds2}, pattern=["a", "b"])
To achieve a more complicated interleaving pattern, for example, 2 steps of ds1
followed by 3 step of ds2
:
dataset = InterleaveDataset(datasets=[ds1, ds2], pattern=[0, 0, 1, 1, 1])
dataset = InterleaveDataset(datasets={"a": ds1, "b": ds2}, pattern=["a", "a", "b", "b", "b"])
When datasets are provided as a dictionary, users can use its key as ds_id
in other Pipeline Operators to apply
dataset-specific operations (such as batching or preprocessing). For example, if we need ds1
to go through
Minmax
then form a batch of 32, and ds2
to use Zscore
then form a batch of 64:
dataset = InterleaveDataset(datasets={"a": ds1, "b": ds2}, pattern=["a", "b"])
pipeline = fe.Pipeline(train_data = dataset,
ops=[Minmax(..., ds_id="a"),
Zscore(..., ds_id="b"),
Batch(batch_size=32, ds_id="a"),
Batch(batch_size=64, ds_id="b")])
Important Limitations
- If any keys are not common between all of your 'datasets' you should not try to use those keys later in Network or Traces.
- If you are using RemoveIf to filter data, an entire pattern-worth of data will be dropped every time that an undesired element is encountered. This means your pipeline processing will be very inefficient and you will almost certainly want to use replacement=True to ensure you don't just wipe out your entire epoch.
- If you use a BatchOp in your pipeline, all subsequent batch-based pipeline ops must be common across all of your interleaved datasets. Any batch padding values must also be the same across all datasets.
- InterleaveDataset always behaves as if drop_last is True for each of its constituent datasets.
Limitations 2, 3, and 4 are expected to be removed once https://github.com/pytorch/pytorch/issues/104761 is fixed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datasets |
Union[Mapping[str, Dataset], Sequence[Dataset]]
|
List of datasets or a dictionary with key being the dataset name, value being the dataset. |
required |
pattern |
Optional[Union[List[str], List[int]]]
|
The step-wise interleaving patterns. When datasets provided is a list, it requires list of integer
when |
None
|
Source code in fastestimator/fastestimator/dataset/interleave_dataset.py
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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
fe_reset_ds
¶
Rearrange the index maps of this InterleaveDataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shuffle |
bool
|
Whether to shuffle the dataset. If False the method will do nothing so long as index maps already exist. |
True
|
seed |
Optional[int]
|
A random seed to control the shuffling. This is provided for compatibility with the dataset.split method random seed. It's not necessary from a training functionality perspective since shuffling is performed every epoch, but if user wants to visualize a dataset element after the split this will help. |
None
|
This method is invoked by the FEDataLoader which allows each epoch to have different random pairings of the basis datasets.
Source code in fastestimator/fastestimator/dataset/interleave_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. |
()
|
seed |
Optional[int]
|
The random seed to use when splitting the dataset. Useful if you want consistent splits across multiple experiments. This isn't necessary if you are splitting by data index. |
None
|
stratify |
Optional[str]
|
A class key within the dataset with which to stratify the split (to approximately maintain class balance ratios before and after a split). Incompatible with data index splitting. |
None
|
Returns:
Type | Description |
---|---|
Union[Self, List[Self]]
|
One or more new datasets which are created by removing elements from the current dataset. The number of |
Union[Self, List[Self]]
|
datasets returned will be equal to the number of |
Union[Self, List[Self]]
|
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/interleave_dataset.py
summary
¶
Generate a summary representation of this dataset. Returns: A summary representation of this dataset.