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 python dict mapping keys expected from the generator to instances of tf.FixedLenFeature, or tf.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 of SparseFeature or VarLenFeature (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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部