示例#1
0
 def prefetch(self, buffer_size):
     """Creates a `Dataset` that prefetches elements from this dataset.
 Args:
   buffer_size: A `tf.int64` scalar `tf.Tensor`, representing the
     maximum number elements that will be buffered when prefetching.
 Returns:
   A `Dataset`.
 """
     return Dataset(dataset_ops.PrefetchDataset(self._dataset, buffer_size))
示例#2
0
def _create_device_dataset(prototype_ds, incarnation_id, prefetch_buffer_size,
                           experimental_slack):
  """Uses _prototype_device_datasets[i] to build a dataset for the device."""
  ds = _ReincarnatedPerDeviceGenerator(prototype_ds, incarnation_id)
  if prefetch_buffer_size > 0:
    if experimental_slack:
      ds = dataset_ops.PrefetchDataset(ds, prefetch_buffer_size, slack_period=1)
    else:
      ds = ds.prefetch(prefetch_buffer_size)
  return ds
def _create_device_dataset(prototype_ds, incarnation_id, prefetch_buffer_size,
                           experimental_slack):
  """Uses _prototype_device_datasets[i] to build a dataset for the device."""
  ds = _ReincarnatedPerDeviceGenerator(prototype_ds, incarnation_id)
  if prefetch_buffer_size > 0:
    if experimental_slack:
      ds = dataset_ops.PrefetchDataset(ds, prefetch_buffer_size, slack_period=1)
    else:
      ds = ds.prefetch(prefetch_buffer_size)
  # TODO(jsimsa): Enable auto-tuning and optimizations when supported for
  # non-CPU devices.
  options = dataset_ops.Options()
  options.experimental_optimization.apply_default_optimizations = False
  options.experimental_optimization.autotune = False
  ds = ds.with_options(options)
  return ds
示例#4
0
 def testPrefetchWithSlack(self, buffer_size, slack_period):
   dataset = dataset_ops.Dataset.range(100)
   dataset = dataset_ops.PrefetchDataset(
       dataset, buffer_size, slack_period=slack_period)
   self.assertDatasetProduces(dataset, expected_output=range(100))