MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / shuffle_batch

Function shuffle_batch

tensorflow/python/training/input.py:1251–1347  ·  view source on GitHub ↗

Creates batches by randomly shuffling tensors. This function adds the following to the current `Graph`: * A shuffling queue into which tensors from `tensors` are enqueued. * A `dequeue_many` operation to create batches from the queue. * A `QueueRunner` to `QUEUE_RUNNER` collection, to enqu

(tensors, batch_size, capacity, min_after_dequeue,
                  num_threads=1, seed=None, enqueue_many=False, shapes=None,
                  allow_smaller_final_batch=False, shared_name=None, name=None)

Source from the content-addressed store, hash-verified

1249 None, "Queue-based input pipelines have been replaced by `tf.data`. Use "
1250 "`tf.data.Dataset.shuffle(min_after_dequeue).batch(batch_size)`.")
1251def shuffle_batch(tensors, batch_size, capacity, min_after_dequeue,
1252 num_threads=1, seed=None, enqueue_many=False, shapes=None,
1253 allow_smaller_final_batch=False, shared_name=None, name=None):
1254 """Creates batches by randomly shuffling tensors.
1255
1256 This function adds the following to the current `Graph`:
1257
1258 * A shuffling queue into which tensors from `tensors` are enqueued.
1259 * A `dequeue_many` operation to create batches from the queue.
1260 * A `QueueRunner` to `QUEUE_RUNNER` collection, to enqueue the tensors
1261 from `tensors`.
1262
1263 If `enqueue_many` is `False`, `tensors` is assumed to represent a
1264 single example. An input tensor with shape `[x, y, z]` will be output
1265 as a tensor with shape `[batch_size, x, y, z]`.
1266
1267 If `enqueue_many` is `True`, `tensors` is assumed to represent a
1268 batch of examples, where the first dimension is indexed by example,
1269 and all members of `tensors` should have the same size in the
1270 first dimension. If an input tensor has shape `[*, x, y, z]`, the
1271 output will have shape `[batch_size, x, y, z]`.
1272
1273 The `capacity` argument controls the how long the prefetching is allowed to
1274 grow the queues.
1275
1276 The returned operation is a dequeue operation and will throw
1277 `tf.errors.OutOfRangeError` if the input queue is exhausted. If this
1278 operation is feeding another input queue, its queue runner will catch
1279 this exception, however, if this operation is used in your main thread
1280 you are responsible for catching this yourself.
1281
1282 For example:
1283
1284 ```python
1285 # Creates batches of 32 images and 32 labels.
1286 image_batch, label_batch = tf.compat.v1.train.shuffle_batch(
1287 [single_image, single_label],
1288 batch_size=32,
1289 num_threads=4,
1290 capacity=50000,
1291 min_after_dequeue=10000)
1292 ```
1293
1294 *N.B.:* You must ensure that either (i) the `shapes` argument is
1295 passed, or (ii) all of the tensors in `tensors` must have
1296 fully-defined shapes. `ValueError` will be raised if neither of
1297 these conditions holds.
1298
1299 If `allow_smaller_final_batch` is `True`, a smaller batch value than
1300 `batch_size` is returned when the queue is closed and there are not enough
1301 elements to fill the batch, otherwise the pending elements are discarded.
1302 In addition, all output tensors' static shapes, as accessed via the
1303 `shape` property will have a first `Dimension` value of `None`, and
1304 operations that depend on fixed batch_size would fail.
1305
1306 Args:
1307 tensors: The list or dictionary of tensors to enqueue.
1308 batch_size: The new batch size pulled from the queue.

Callers

nothing calls this directly

Calls 1

_shuffle_batchFunction · 0.85

Tested by

no test coverage detected