tf.FIFOQueue

Class FIFOQueue

Inherits From: QueueBase

Defined in tensorflow/python/ops/data_flow_ops.py.

See the guides: Inputs and Readers > Queues, Threading and Queues > Queue usage overview, Threading and Queues

A queue implementation that dequeues elements in first-in first-out order.

See tf.QueueBase for a description of the methods onthis class.

Properties

dtypes

The list of dtypes for each component of a queue element.

name

The name of the underlying queue.

names

The list of names for each component of a queue element.

queue_ref

The underlying queue reference.

shapes

The list of shapes for each component of a queue element.

Methods

__init__

__init__(
    capacity,
    dtypes,
    shapes=None,
    names=None,
    shared_name=None,
    name='fifo_queue'
)

Creates a queue that dequeues elements in a first-in first-out order.

A FIFOQueue has bounded capacity; supports multiple concurrentproducers and consumers; and provides exactly-once delivery.

A FIFOQueue holds a list of up to capacity elements. Eachelement is a fixed-length tuple of tensors whose dtypes aredescribed by dtypes, and whose shapes are optionally describedby the shapes argument.

If the shapes argument is specified, each component of a queueelement must have the respective fixed shape. If it isunspecified, different queue elements may have different shapes,but the use of dequeue_many is disallowed.

Args:
  • capacity: An integer. The upper bound on the number of elements that may be stored in this queue.
  • dtypes: A list of DType objects. The length of dtypes must equal the number of tensors in each queue element.
  • shapes: (Optional.) A list of fully-defined TensorShape objects with the same length as dtypes, or None.
  • names: (Optional.) A list of string naming the components in the queue with the same length as dtypes, or None. If specified the dequeue methods return a dictionary with the names as keys.
  • shared_name: (Optional.) If non-empty, this queue will be shared under the given name across multiple sessions.
  • name: Optional name for the queue operation.

close

close(
    cancel_pending_enqueues=False,
    name=None
)

Closes this queue.

This operation signals that no more elements will be enqueued inthe given queue. Subsequent enqueue and enqueue_manyoperations will fail. Subsequent dequeue and dequeue_manyoperations will continue to succeed if sufficient elements remainin the queue. Subsequently dequeue and dequeue_many operationsthat would otherwise block waiting for more elements (if closehadn't been called) will now fail immediately.

If cancel_pending_enqueues is True, all pending requests will alsobe canceled.

Args:
  • cancel_pending_enqueues: (Optional.) A boolean, defaulting to False (described above).
  • name: A name for the operation (optional).
Returns:

The operation that closes the queue.

dequeue

dequeue(name=None)

Dequeues one element from this queue.

If the queue is empty when this operation executes, it will blockuntil there is an element to dequeue.

At runtime, this operation may raise an error if the queue istf.QueueBase.close before or during its execution. If thequeue is closed, the queue is empty, and there are no pendingenqueue operations that can fulfill this request,tf.errors.OutOfRangeError will be raised. If the session istf.Session.close,tf.errors.CancelledError will be raised.

Args:
  • name: A name for the operation (optional).
Returns:

The tuple of tensors that was dequeued.

dequeue_many

dequeue_many(
    n,
    name=None
)

Dequeues and concatenates n elements from this queue.

This operation concatenates queue-element component tensors alongthe 0th dimension to make a single component tensor. All of thecomponents in the dequeued tuple will have size n in the 0th dimension.

If the queue is closed and there are less than n elements left, then anOutOfRange exception is raised.

At runtime, this operation may raise an error if the queue istf.QueueBase.close before or during its execution. If thequeue is closed, the queue contains fewer than n elements, andthere are no pending enqueue operations that can fulfill thisrequest, tf.errors.OutOfRangeError will be raised. If thesession is tf.Session.close,tf.errors.CancelledError will be raised.

Args:
  • n: A scalar Tensor containing the number of elements to dequeue.
  • name: A name for the operation (optional).
Returns:

The tuple of concatenated tensors that was dequeued.

dequeue_up_to

dequeue_up_to(
    n,
    name=None
)

Dequeues and concatenates n elements from this queue.

Note This operation is not supported by all queues. If a queue does notsupport DequeueUpTo, then a tf.errors.UnimplementedError is raised.

This operation concatenates queue-element component tensors alongthe 0th dimension to make a single component tensor. If the queuehas not been closed, all of the components in the dequeued tuplewill have size n in the 0th dimension.

If the queue is closed and there are more than 0 but fewer thann elements remaining, then instead of raising atf.errors.OutOfRangeError like tf.QueueBase.dequeue_many,less than n elements are returned immediately. If the queue isclosed and there are 0 elements left in the queue, then atf.errors.OutOfRangeError is raised just like in dequeue_many.Otherwise the behavior is identical to dequeue_many.

Args:
  • n: A scalar Tensor containing the number of elements to dequeue.
  • name: A name for the operation (optional).
Returns:

The tuple of concatenated tensors that was dequeued.

enqueue

enqueue(
    vals,
    name=None
)

Enqueues one element to this queue.

If the queue is full when this operation executes, it will blockuntil the element has been enqueued.

At runtime, this operation may raise an error if the queue istf.QueueBase.close before or during its execution. If thequeue is closed before this operation runs,tf.errors.CancelledError will be raised. If this operation isblocked, and either (i) the queue is closed by a close operationwith cancel_pending_enqueues=True, or (ii) the session istf.Session.close,tf.errors.CancelledError will be raised.

Args:
  • vals: A tensor, a list or tuple of tensors, or a dictionary containing the values to enqueue.
  • name: A name for the operation (optional).
Returns:

The operation that enqueues a new tuple of tensors to the queue.

enqueue_many

enqueue_many(
    vals,
    name=None
)

Enqueues zero or more elements to this queue.

This operation slices each component tensor along the 0th dimension tomake multiple queue elements. All of the tensors in vals must have thesame size in the 0th dimension.

If the queue is full when this operation executes, it will blockuntil all of the elements have been enqueued.

At runtime, this operation may raise an error if the queue istf.QueueBase.close before or during its execution. If thequeue is closed before this operation runs,tf.errors.CancelledError will be raised. If this operation isblocked, and either (i) the queue is closed by a close operationwith cancel_pending_enqueues=True, or (ii) the session istf.Session.close,tf.errors.CancelledError will be raised.

Args:
  • vals: A tensor, a list or tuple of tensors, or a dictionary from which the queue elements are taken.
  • name: A name for the operation (optional).
Returns:

The operation that enqueues a batch of tuples of tensors to the queue.

from_list

from_list(
    index,
    queues
)

Create a queue using the queue reference from queues[index].

Args:
  • index: An integer scalar tensor that determines the input that gets selected.
  • queues: A list of QueueBase objects.
Returns:

A QueueBase object.

Raises:
  • TypeError: When queues is not a list of QueueBase objects, or when the data types of queues are not all the same.

is_closed

is_closed(name=None)

Returns true if queue is closed.

This operation returns true if the queue is closed and false if the queueis open.

Args:
  • name: A name for the operation (optional).
Returns:

True if the queue is closed and false if the queue is open.

size

size(name=None)

Compute the number of elements in this queue.

Args:
  • name: A name for the operation (optional).
Returns:

A scalar tensor containing the number of elements in this queue.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值