MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / unbatch

Method unbatch

tensorflow/python/data/ops/dataset_ops.py:1592–1634  ·  view source on GitHub ↗

Splits elements of a dataset into multiple elements. For example, if elements of the dataset are shaped `[B, a0, a1, ...]`, where `B` may vary for each input element, then for each element in the dataset, the unbatched dataset will contain `B` consecutive elements of shape `[a0, a1,

(self)

Source from the content-addressed store, hash-verified

1590 output_types=structure.get_flat_tensor_types(state_structure)))
1591
1592 def unbatch(self):
1593 """Splits elements of a dataset into multiple elements.
1594
1595 For example, if elements of the dataset are shaped `[B, a0, a1, ...]`,
1596 where `B` may vary for each input element, then for each element in the
1597 dataset, the unbatched dataset will contain `B` consecutive elements
1598 of shape `[a0, a1, ...]`.
1599
1600 ```python
1601 # NOTE: The following example uses `{ ... }` to represent the contents
1602 # of a dataset.
1603 ds = { ['a', 'b', 'c'], ['a', 'b'], ['a', 'b', 'c', 'd'] }
1604
1605 ds.unbatch() == {'a', 'b', 'c', 'a', 'b', 'a', 'b', 'c', 'd'}
1606 ```
1607
1608 Returns:
1609 A `Dataset` transformation function, which can be passed to
1610 `tf.data.Dataset.apply`.
1611 """
1612
1613 # NOTE(mrry): We must ensure that any non-tensor components in `dataset`
1614 # are normalized to their dense tensor representation, so that the
1615 # non-tensor oblivious unbatching logic will slice them appropriately.
1616 # This leads to a somewhat inefficient re-encoding step for all non-tensor
1617 # components.
1618 #
1619 # TODO(mrry): Consider optimizing this if it turns out to be a bottleneck.
1620 def normalize(arg, *rest):
1621 # pylint: disable=protected-access
1622 if rest:
1623 return structure.to_batched_tensor_list(self.element_spec,
1624 (arg,) + rest)
1625 else:
1626 return structure.to_batched_tensor_list(self.element_spec, arg)
1627
1628 normalized_dataset = self.map(normalize)
1629
1630 # NOTE(mrry): Our `map()` has lost information about the structure of
1631 # non-tensor components, so re-apply the structure of the original dataset.
1632 restructured_dataset = _RestructuredDataset(normalized_dataset,
1633 self.element_spec)
1634 return _UnbatchDataset(restructured_dataset)
1635
1636 def with_options(self, options):
1637 """Returns a new `tf.data.Dataset` with the given options set.

Callers 15

_BatchGradFunction · 0.80
decoratedFunction · 0.80
testUnbatchGradMethod · 0.80
unbatchFunction · 0.80
StreamingFilesDatasetFunction · 0.80
testBasicUnbatchMethod · 0.80
testUnbatchTimeoutMethod · 0.80

Calls 3

mapMethod · 0.95
_UnbatchDatasetClass · 0.85