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

Function maybe_batch

tensorflow/python/training/input.py:1028–1077  ·  view source on GitHub ↗

Conditionally creates batches of tensors based on `keep_input`. See docstring in `batch` for more details. Args: tensors: The list or dictionary of tensors to enqueue. keep_input: A `bool` Tensor. This tensor controls whether the input is added to the queue or not. If it is a s

(tensors, keep_input, batch_size, num_threads=1, capacity=32,
                enqueue_many=False, shapes=None, dynamic_pad=False,
                allow_smaller_final_batch=False, shared_name=None, name=None)

Source from the content-addressed store, hash-verified

1026 "`tf.data.Dataset.filter(...).batch(batch_size)` (or `padded_batch(...)`"
1027 " if `dynamic_pad=True`).")
1028def maybe_batch(tensors, keep_input, batch_size, num_threads=1, capacity=32,
1029 enqueue_many=False, shapes=None, dynamic_pad=False,
1030 allow_smaller_final_batch=False, shared_name=None, name=None):
1031 """Conditionally creates batches of tensors based on `keep_input`.
1032
1033 See docstring in `batch` for more details.
1034
1035 Args:
1036 tensors: The list or dictionary of tensors to enqueue.
1037 keep_input: A `bool` Tensor. This tensor controls whether the input is
1038 added to the queue or not. If it is a scalar and evaluates `True`, then
1039 `tensors` are all added to the queue. If it is a vector and `enqueue_many`
1040 is `True`, then each example is added to the queue only if the
1041 corresponding value in `keep_input` is `True`. This tensor essentially
1042 acts as a filtering mechanism.
1043 batch_size: The new batch size pulled from the queue.
1044 num_threads: The number of threads enqueuing `tensors`. The batching will
1045 be nondeterministic if `num_threads > 1`.
1046 capacity: An integer. The maximum number of elements in the queue.
1047 enqueue_many: Whether each tensor in `tensors` is a single example.
1048 shapes: (Optional) The shapes for each example. Defaults to the
1049 inferred shapes for `tensors`.
1050 dynamic_pad: Boolean. Allow variable dimensions in input shapes.
1051 The given dimensions are padded upon dequeue so that tensors within a
1052 batch have the same shapes.
1053 allow_smaller_final_batch: (Optional) Boolean. If `True`, allow the final
1054 batch to be smaller if there are insufficient items left in the queue.
1055 shared_name: (Optional). If set, this queue will be shared under the given
1056 name across multiple sessions.
1057 name: (Optional) A name for the operations.
1058
1059 Returns:
1060 A list or dictionary of tensors with the same types as `tensors`.
1061
1062 Raises:
1063 ValueError: If the `shapes` are not specified, and cannot be
1064 inferred from the elements of `tensors`.
1065 """
1066 return _batch(
1067 tensors,
1068 batch_size,
1069 keep_input,
1070 num_threads=num_threads,
1071 capacity=capacity,
1072 enqueue_many=enqueue_many,
1073 shapes=shapes,
1074 dynamic_pad=dynamic_pad,
1075 allow_smaller_final_batch=allow_smaller_final_batch,
1076 shared_name=shared_name,
1077 name=name)
1078
1079
1080@tf_export(v1=["train.batch_join"])

Callers

nothing calls this directly

Calls 1

_batchFunction · 0.85

Tested by

no test coverage detected