MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / from_structure

Method from_structure

tensorflow/python/data/ops/iterator_ops.py:119–220  ·  view source on GitHub ↗

Creates a new, uninitialized `Iterator` with the given structure. This iterator-constructing method can be used to create an iterator that is reusable with many different datasets. The returned iterator is not bound to a particular dataset, and it has no `initializer`. To initializ

(output_types,
                     output_shapes=None,
                     shared_name=None,
                     output_classes=None)

Source from the content-addressed store, hash-verified

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
133
134 ```python
135 iterator = Iterator.from_structure(tf.int64, tf.TensorShape([]))
136
137 dataset_range = Dataset.range(10)
138 range_initializer = iterator.make_initializer(dataset_range)
139
140 dataset_evens = dataset_range.filter(lambda x: x % 2 == 0)
141 evens_initializer = iterator.make_initializer(dataset_evens)
142
143 # Define a model based on the iterator; in this example, the model_fn
144 # is expected to take scalar tf.int64 Tensors as input (see
145 # the definition of 'iterator' above).
146 prediction, loss = model_fn(iterator.get_next())
147
148 # Train for `num_epochs`, where for each epoch, we first iterate over
149 # dataset_range, and then iterate over dataset_evens.
150 for _ in range(num_epochs):
151 # Initialize the iterator to `dataset_range`
152 sess.run(range_initializer)
153 while True:
154 try:
155 pred, loss_val = sess.run([prediction, loss])
156 except tf.errors.OutOfRangeError:
157 break
158
159 # Initialize the iterator to `dataset_evens`
160 sess.run(evens_initializer)
161 while True:
162 try:
163 pred, loss_val = sess.run([prediction, loss])
164 except tf.errors.OutOfRangeError:
165 break
166 ```
167
168 Args:
169 output_types: A nested structure of `tf.DType` objects corresponding to
170 each component of an element of this dataset.
171 output_shapes: (Optional.) A nested structure of `tf.TensorShape` objects
172 corresponding to each component of an element of this dataset. If
173 omitted, each component will have an unconstrainted shape.
174 shared_name: (Optional.) If non-empty, this iterator will be shared under
175 the given name across multiple sessions that share the same devices
176 (e.g. when using a remote server).

Callers 15

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 3

_device_stack_is_emptyFunction · 0.85
IteratorClass · 0.70
deviceMethod · 0.45