Base class for queue implementations. A queue is a TensorFlow data structure that stores tensors across multiple steps, and exposes operations that enqueue and dequeue tensors. Each queue element is a tuple of one or more tensors, where each tuple component has a static dtype, and may ha
| 118 | v1=["queue.QueueBase", "io.QueueBase", "QueueBase"]) |
| 119 | @deprecation.deprecated_endpoints(["io.QueueBase", "QueueBase"]) |
| 120 | class QueueBase(object): |
| 121 | """Base class for queue implementations. |
| 122 | |
| 123 | A queue is a TensorFlow data structure that stores tensors across |
| 124 | multiple steps, and exposes operations that enqueue and dequeue |
| 125 | tensors. |
| 126 | |
| 127 | Each queue element is a tuple of one or more tensors, where each |
| 128 | tuple component has a static dtype, and may have a static shape. The |
| 129 | queue implementations support versions of enqueue and dequeue that |
| 130 | handle single elements, versions that support enqueuing and |
| 131 | dequeuing a batch of elements at once. |
| 132 | |
| 133 | See `tf.queue.FIFOQueue` and |
| 134 | `tf.queue.RandomShuffleQueue` for concrete |
| 135 | implementations of this class, and instructions on how to create |
| 136 | them. |
| 137 | """ |
| 138 | |
| 139 | def __init__(self, dtypes, shapes, names, queue_ref): |
| 140 | """Constructs a queue object from a queue reference. |
| 141 | |
| 142 | The two optional lists, `shapes` and `names`, must be of the same length |
| 143 | as `dtypes` if provided. The values at a given index `i` indicate the |
| 144 | shape and name to use for the corresponding queue component in `dtypes`. |
| 145 | |
| 146 | Args: |
| 147 | dtypes: A list of types. The length of dtypes must equal the number |
| 148 | of tensors in each element. |
| 149 | shapes: Constraints on the shapes of tensors in an element: |
| 150 | A list of shape tuples or None. This list is the same length |
| 151 | as dtypes. If the shape of any tensors in the element are constrained, |
| 152 | all must be; shapes can be None if the shapes should not be constrained. |
| 153 | names: Optional list of names. If provided, the `enqueue()` and |
| 154 | `dequeue()` methods will use dictionaries with these names as keys. |
| 155 | Must be None or a list or tuple of the same length as `dtypes`. |
| 156 | queue_ref: The queue reference, i.e. the output of the queue op. |
| 157 | |
| 158 | Raises: |
| 159 | ValueError: If one of the arguments is invalid. |
| 160 | """ |
| 161 | self._dtypes = dtypes |
| 162 | if shapes is not None: |
| 163 | if len(shapes) != len(dtypes): |
| 164 | raise ValueError("Queue shapes must have the same length as dtypes") |
| 165 | self._shapes = [tensor_shape.TensorShape(s) for s in shapes] |
| 166 | else: |
| 167 | self._shapes = [tensor_shape.unknown_shape() for _ in self._dtypes] |
| 168 | if names is not None: |
| 169 | if len(names) != len(dtypes): |
| 170 | raise ValueError("Queue names must have the same length as dtypes") |
| 171 | self._names = names |
| 172 | else: |
| 173 | self._names = None |
| 174 | self._queue_ref = queue_ref |
| 175 | if context.executing_eagerly(): |
| 176 | if context.context().scope_name: |
| 177 | self._name = context.context().scope_name |