Generates a tf.data.Dataset object.
(self,
input_context: Optional[tf.distribute.InputContext] = None,
dataset: Optional[tf.data.Dataset] = None)
| 567 | return dataset |
| 568 | |
| 569 | def read(self, |
| 570 | input_context: Optional[tf.distribute.InputContext] = None, |
| 571 | dataset: Optional[tf.data.Dataset] = None) -> tf.data.Dataset: |
| 572 | """Generates a tf.data.Dataset object.""" |
| 573 | if dataset is None: |
| 574 | dataset = self._read_data_source(self._matched_files, self._dataset_fn, |
| 575 | input_context) |
| 576 | dataset = self._decode_and_parse_dataset(dataset, self._global_batch_size, |
| 577 | input_context) |
| 578 | dataset = _maybe_map_fn(dataset, self._postprocess_fn) |
| 579 | if not (self._enable_shared_tf_data_service_between_parallel_trainers and |
| 580 | self._apply_tf_data_service_before_batching): |
| 581 | dataset = self._maybe_apply_data_service(dataset, input_context) |
| 582 | |
| 583 | if self._deterministic is not None: |
| 584 | options = tf.data.Options() |
| 585 | options.deterministic = self._deterministic |
| 586 | dataset = dataset.with_options(options) |
| 587 | if self._autotune_algorithm: |
| 588 | options = tf.data.Options() |
| 589 | options.autotune.autotune_algorithm = ( |
| 590 | tf.data.experimental.AutotuneAlgorithm[self._autotune_algorithm] |
| 591 | ) |
| 592 | dataset = dataset.with_options(options) |
| 593 | |
| 594 | if self._ram_budget: |
| 595 | options = tf.data.Options() |
| 596 | options.autotune.ram_budget = self._ram_budget * 1024 * 1024 * 1024 |
| 597 | dataset = dataset.with_options(options) |
| 598 | |
| 599 | return dataset.prefetch(self._prefetch_buffer_size) |