Lazy bucketing of input tensors according to `which_bucket`. The argument `tensors` can be a list or a dictionary of tensors. The value returned by the function will be of the same type as `tensors`. The tensors entering this function are put into the bucket given by `which_bucket`. Eac
(tensors,
which_bucket,
batch_size,
num_buckets,
num_threads=1,
capacity=32,
bucket_capacities=None,
shapes=None,
dynamic_pad=False,
allow_smaller_final_batch=False,
keep_input=True,
shared_name=None,
name=None)
| 61 | |
| 62 | |
| 63 | def bucket(tensors, |
| 64 | which_bucket, |
| 65 | batch_size, |
| 66 | num_buckets, |
| 67 | num_threads=1, |
| 68 | capacity=32, |
| 69 | bucket_capacities=None, |
| 70 | shapes=None, |
| 71 | dynamic_pad=False, |
| 72 | allow_smaller_final_batch=False, |
| 73 | keep_input=True, |
| 74 | shared_name=None, |
| 75 | name=None): |
| 76 | """Lazy bucketing of input tensors according to `which_bucket`. |
| 77 | |
| 78 | The argument `tensors` can be a list or a dictionary of tensors. |
| 79 | The value returned by the function will be of the same type |
| 80 | as `tensors`. |
| 81 | |
| 82 | The tensors entering this function are put into the bucket given by |
| 83 | `which_bucket`. Each bucket has its own queue. When a bucket contains |
| 84 | `batch_size` elements, this minibatch is pushed onto a top queue. The |
| 85 | tensors returned from this function are a the result of dequeueing the |
| 86 | next minibatch from this top queue. |
| 87 | |
| 88 | This function is implemented using several queues. A `QueueRunner` for the |
| 89 | queues is added to the current `Graph`'s `QUEUE_RUNNER` collection. |
| 90 | |
| 91 | As the returned tensors are the result of a dequeue operation, evaluating |
| 92 | them will throw a `tf.errors.OutOfRangeError` when the input queue is |
| 93 | exhausted. If these tensors are feeding another input queue, its queue runner |
| 94 | will catch this exception, however, if they are used in your main thread |
| 95 | you are responsible for catching this yourself. |
| 96 | |
| 97 | *N.B.:* If `dynamic_pad` is `False`, you must ensure that either |
| 98 | (i) the `shapes` argument is passed, or (ii) all of the tensors in |
| 99 | `tensors` must have fully-defined shapes. `ValueError` will be |
| 100 | raised if neither of these conditions holds. |
| 101 | |
| 102 | If `dynamic_pad` is `True`, it is sufficient that the *rank* of the |
| 103 | tensors is known, but individual dimensions may have shape `None`. |
| 104 | In this case, for each enqueue the dimensions with value `None` |
| 105 | may have a variable length; upon dequeue, the output tensors will be padded |
| 106 | on the right to the maximum shape of the tensors in the current minibatch. |
| 107 | For numbers, this padding takes value 0. For strings, this padding is |
| 108 | the empty string. See `PaddingFIFOQueue` for more info. |
| 109 | |
| 110 | If `allow_smaller_final_batch` is `True`, a smaller batch value than |
| 111 | `batch_size` is returned when the queues are closed and there are not enough |
| 112 | elements to fill the batch, otherwise the pending elements are discarded. |
| 113 | In addition, all output tensors' static shapes, as accessed via the |
| 114 | `get_shape()` method will have a 0th `Dimension` value of `None`, and |
| 115 | operations that depend on fixed batch_size would fail. |
| 116 | |
| 117 | Args: |
| 118 | tensors: The list or dictionary of tensors, representing a single element, |
| 119 | to bucket. Nested lists are not supported. |
| 120 | which_bucket: An `int32` scalar Tensor taking a value in `[0, num_buckets)`. |
no test coverage detected