slicer
Slicer
¶
A base class for FastEstimator Slicers.
Slicers cut batches into mini-batches in order to pass them through the network, then re-assemble them after bringing all of the pieces back together on the CPU before handing them off to network post-processing and traces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slice |
Union[None, str, Sequence[str]]
|
The input key(s) which this Slicer slices. Data which this slicer does not cut will be replicated across the resulting minibatches so that the network ops always have access to all of the batch keys. |
None
|
unslice |
Union[None, str, Sequence[str]]
|
The input key(s) which this Slicer un-slices. By default (empty tuple) the Slicer will un-slice
whatever keys were specified in |
()
|
mode |
Union[None, str, Iterable[str]]
|
What mode(s) to invoke this Slicer in. For example, "train", "eval", "test", or "infer". To invoke regardless of mode, pass None. To invoke in all modes except for a particular one, you can pass an argument like "!infer" or "!train". |
None
|
ds_id |
Union[None, str, Iterable[str]]
|
What dataset id(s) to invoke this Slicer in. To invoke regardless of ds_id, pass None. To invoke in all ds_ids except for a particular one, you can pass an argument like "!ds1". |
None
|
Source code in fastestimator/fastestimator/slicer/slicer.py
slice_batches
¶
A method to convert one or more data tensors into slices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batches |
Tuple[Tensor, ...]
|
One or more data tensors, in a 1-1 relationship with self.slice_inputs |
required |
Returns:
Type | Description |
---|---|
List[Tuple[Tensor, ...]]
|
The slices corresponding to each of the input batch(es) |
Source code in fastestimator/fastestimator/slicer/slicer.py
forward_slicers
¶
Perform a forward pass over a list of slicers, cutting a batch of data apart into multiple mini-batches.
Any data (keys) which are not explicitly handled by a Slicer in the input list will simply be replicated across all of the mini-batches produced by this function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slicers |
List[Slicer]
|
The slicers with which to cut apart the batch. |
required |
data |
MutableMapping[str, Tensor]
|
The batch to be cut apart. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the slicers produce an inconsistent number of mini-batches. |
Returns:
Type | Description |
---|---|
List[Dict[str, Tensor]]
|
A list of mini-batches created by slicing the input batch. |
Source code in fastestimator/fastestimator/slicer/slicer.py
reverse_slicers
¶
Compile a list of mini-batches back into a single batch of data, according to a given list of slicers.
Note that the data
provided need not contain all of the keys requested by the slicer.unslice_inputs. Missing keys
will simply be skipped, with the assumption that the user does not care about that data down-stream. Any data not
explicitly handled by a slicer here will be passed back based on its value in original_data
or else the first
occurrence in the data
list, with any differing values in subsequent mini-batches being ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slicers |
List[Slicer]
|
The slicers to use when re-combining the mini-batches |
required |
data |
List[MutableMapping[str, Tensor]]
|
A list of mini-batches. |
required |
original_data |
Dict[str, Tensor]
|
The pre-sliced data. Used as a fallback when slicers don't handle un-slicing things. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Tensor]
|
A single combined batch of data. |
Source code in fastestimator/fastestimator/slicer/slicer.py
sanity_assert_slicers
¶
A sanity test to ensure that slicers in a given list don't interfere with each-other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slicers |
List[Slicer]
|
The slicers to be run during a given batch. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If multiple slicers attempt to slice/unslice the same keys simultaneously. |