(dataset, start=1)
return dataset.map(map_fn)
Add a random offset to the dataset.

  Args:
    dataset: `tf.data.Dataset` object that contains tuples (features, labels),
        where `features` is a Python dictionary.
    start: A starting value for the global offset. Optional.

  Returns:
    A new `tf.data.Dataset` object with a extra feature for the random offset.
Add a random offset to the dataset.
Add a random offset to the dataset .
def add_random_offset_to_features(dataset, start=1):
  """Add a random offset to the dataset.

  Args:
    dataset: `tf.data.Dataset` object that contains tuples (features, labels),
        where `features` is a Python dictionary.
    start: A starting value for the global offset. Optional.

  Returns:
    A new `tf.data.Dataset` object with a extra feature for the random offset.
  """
  dataset = dataset.apply(tf.data.experimental.enumerate_dataset(start=start))
  def map_fn(offset, data):
    offset = tf.cast(offset, tf.int32)
    if isinstance(data, tuple) and len(data) == 2 and isinstance(data[0], dict):
      # Data is a tuple (features, labels) as expected by the Estimator
      # interface.
      logging.info("Passing random offset: %s with data %s.", offset, data)
      features, labels = data
      features[_RANDOM_OFFSET_FEATURE_KEY] = offset
      return features, labels
    raise ValueError("Data in dataset must be a tuple (features, labels) and "
                     "features must be a Python dictionary. data was {}".format(
                         data))
  return dataset.map(map_fn)
def add_random_offset_to_features ( dataset , start = 1 ) : dataset = dataset . apply ( tf . data . experimental . enumerate_dataset ( start = start ) ) def map_fn ( offset , data ) : offset = tf . cast ( offset , tf . int32 ) if isinstance ( data , tuple ) and len ( data ) == 2 and isinstance ( data [ 0 ] , dict ) : # Data is a tuple (features, labels) as expected by the Estimator # interface. logging . info ( "Passing random offset: %s with data %s." , offset , data ) features , labels = data features [ _RANDOM_OFFSET_FEATURE_KEY ] = offset return features , labels raise ValueError ( "Data in dataset must be a tuple (features, labels) and " "features must be a Python dictionary. data was {}" . format ( data ) ) return dataset . map ( map_fn )