1# Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Enumerate dataset transformations.""" 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20from tensorflow.python.util import deprecation 21from tensorflow.python.util.tf_export import tf_export 22 23 24@deprecation.deprecated(None, "Use `tf.data.Dataset.enumerate()`.") 25@tf_export("data.experimental.enumerate_dataset") 26def enumerate_dataset(start=0): 27 """A transformation that enumerates the elements of a dataset. 28 29 It is similar to python's `enumerate`. 30 For example: 31 32 ```python 33 # NOTE: The following examples use `{ ... }` to represent the 34 # contents of a dataset. 35 a = { 1, 2, 3 } 36 b = { (7, 8), (9, 10) } 37 38 # The nested structure of the `datasets` argument determines the 39 # structure of elements in the resulting dataset. 40 a.apply(tf.data.experimental.enumerate_dataset(start=5)) 41 => { (5, 1), (6, 2), (7, 3) } 42 b.apply(tf.data.experimental.enumerate_dataset()) 43 => { (0, (7, 8)), (1, (9, 10)) } 44 ``` 45 46 Args: 47 start: A `tf.int64` scalar `tf.Tensor`, representing the start value for 48 enumeration. 49 50 Returns: 51 A `Dataset` transformation function, which can be passed to 52 `tf.data.Dataset.apply`. 53 """ 54 55 def _apply_fn(dataset): 56 return dataset.enumerate(start) 57 58 return _apply_fn 59