Represents the state of iterating through a `Dataset`.
| 73 | |
| 74 | @tf_export(v1=["data.Iterator"]) |
| 75 | class Iterator(trackable.Trackable): |
| 76 | """Represents the state of iterating through a `Dataset`.""" |
| 77 | |
| 78 | def __init__(self, iterator_resource, initializer, output_types, |
| 79 | output_shapes, output_classes): |
| 80 | """Creates a new iterator from the given iterator resource. |
| 81 | |
| 82 | Note: Most users will not call this initializer directly, and will |
| 83 | instead use `Dataset.make_initializable_iterator()` or |
| 84 | `Dataset.make_one_shot_iterator()`. |
| 85 | |
| 86 | Args: |
| 87 | iterator_resource: A `tf.resource` scalar `tf.Tensor` representing the |
| 88 | iterator. |
| 89 | initializer: A `tf.Operation` that should be run to initialize this |
| 90 | iterator. |
| 91 | output_types: A nested structure of `tf.DType` objects corresponding to |
| 92 | each component of an element of this iterator. |
| 93 | output_shapes: A nested structure of `tf.TensorShape` objects |
| 94 | corresponding to each component of an element of this iterator. |
| 95 | output_classes: A nested structure of Python `type` objects corresponding |
| 96 | to each component of an element of this iterator. |
| 97 | """ |
| 98 | self._iterator_resource = iterator_resource |
| 99 | self._initializer = initializer |
| 100 | |
| 101 | if (output_types is None or output_shapes is None |
| 102 | or output_classes is None): |
| 103 | raise ValueError("If `structure` is not specified, all of " |
| 104 | "`output_types`, `output_shapes`, and `output_classes`" |
| 105 | " must be specified.") |
| 106 | self._element_spec = structure.convert_legacy_structure( |
| 107 | output_types, output_shapes, output_classes) |
| 108 | self._flat_tensor_shapes = structure.get_flat_tensor_shapes( |
| 109 | self._element_spec) |
| 110 | self._flat_tensor_types = structure.get_flat_tensor_types( |
| 111 | self._element_spec) |
| 112 | |
| 113 | self._string_handle = gen_dataset_ops.iterator_to_string_handle( |
| 114 | self._iterator_resource) |
| 115 | self._get_next_call_count = 0 |
| 116 | ops.add_to_collection(GLOBAL_ITERATORS, self._iterator_resource) |
| 117 | |
| 118 | @staticmethod |
| 119 | def from_structure(output_types, |
| 120 | output_shapes=None, |
| 121 | shared_name=None, |
| 122 | output_classes=None): |
| 123 | """Creates a new, uninitialized `Iterator` with the given structure. |
| 124 | |
| 125 | This iterator-constructing method can be used to create an iterator that |
| 126 | is reusable with many different datasets. |
| 127 | |
| 128 | The returned iterator is not bound to a particular dataset, and it has |
| 129 | no `initializer`. To initialize the iterator, run the operation returned by |
| 130 | `Iterator.make_initializer(dataset)`. |
| 131 | |
| 132 | The following is an example |
no outgoing calls
no test coverage detected