contrib.training.python_input
tf.contrib.training.python_input
tf.contrib.training.python_input
python_input( generator, features, name=None )
Defined in tensorflow/contrib/training/python/training/python_input.py
.
Easily feed data from a python generator into TensorFlow queues.
Example usage:
def generator(): for i in range(3): yield {"value": i} features = { "value": tf.FixedLenFeature(shape=[], dtype=dtypes.int32) } tensor_dict = tf.contrib.training.python_input(generator, features) batched_dict = tf.train.batch( tensor_dict, batch_size=2, allow_smaller_final_batch=True) s = tf.Session() tf.train.start_queue_runners() batch1 = s.run(batched_dict) # returns {"value": np.array([0, 1])} batch2 = s.run(batched_dict) # returns {"value": np.array([2])} s.run(batched_dict) # error: Queue is closed (generator finished at i==3)
Args:
-
generator
: A python generator that takes no arguments, and yields dicts containing a single minibatch entry one at a time. -
features
: A pythondict
mapping keys expected from the generator to instances oftf.FixedLenFeature
, ortf.FixedLenSequenceFeature
. -
name
: (Optional) A name for the operations.
Returns:
A dict mapping keys of the features
dict to Tensor
objects. These Tensor
objects are outputs of a queue that is fed by generator
.
Raises:
-
TypeError
: If generator is not callable or features is not a dict. -
TypeError
: If any of features' values are not a Feature object. -
NotImplementedError
: If any of features' values are instances ofSparseFeature
orVarLenFeature
(these are not currently supported). -
ValueError
: If any FixedLenSequenceFeatures contain a default value (this field is not supported). -
ValueError
: if any FixedLenSequenceFeatures have allow_missing=False (this field is not supported).
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/contrib/training/python_input