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

Function _batch

tensorflow/python/training/input.py:760–791  ·  view source on GitHub ↗

Helper function for `batch` and `maybe_batch`.

(tensors, batch_size, keep_input, 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

758
759
760def _batch(tensors, batch_size, keep_input, num_threads=1, capacity=32,
761 enqueue_many=False, shapes=None, dynamic_pad=False,
762 allow_smaller_final_batch=False, shared_name=None,
763 name=None):
764 """Helper function for `batch` and `maybe_batch`."""
765 if context.executing_eagerly():
766 raise ValueError(
767 "Input pipelines based on Queues are not supported when eager execution"
768 " is enabled. Please use tf.data to ingest data into your model"
769 " instead.")
770 tensor_list = _as_tensor_list(tensors)
771 with ops.name_scope(name, "batch", list(tensor_list) + [keep_input]) as name:
772 tensor_list = _validate(tensor_list)
773 keep_input = _validate_keep_input(keep_input, enqueue_many)
774 (tensor_list, sparse_info) = _store_sparse_tensors(
775 tensor_list, enqueue_many, keep_input)
776 types = _dtypes([tensor_list])
777 shapes = _shapes([tensor_list], shapes, enqueue_many)
778 # TODO(josh11b,mrry): Switch to BatchQueue once it is written.
779 queue = _which_queue(dynamic_pad)(
780 capacity=capacity, dtypes=types, shapes=shapes, shared_name=shared_name)
781 _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input)
782 summary.scalar(
783 "fraction_of_%d_full" % capacity,
784 math_ops.cast(queue.size(), dtypes.float32) * (1. / capacity))
785
786 if allow_smaller_final_batch:
787 dequeued = queue.dequeue_up_to(batch_size, name=name)
788 else:
789 dequeued = queue.dequeue_many(batch_size, name=name)
790 dequeued = _restore_sparse_tensors(dequeued, sparse_info)
791 return _as_original_type(tensors, dequeued)
792
793
794# TODO(josh11b): Add a thread_multiplier or num_threads (that has to be

Callers 2

batchFunction · 0.85
maybe_batchFunction · 0.85

Calls 15

_as_tensor_listFunction · 0.85
_validateFunction · 0.85
_validate_keep_inputFunction · 0.85
_store_sparse_tensorsFunction · 0.85
_dtypesFunction · 0.85
_shapesFunction · 0.85
_enqueueFunction · 0.85
_restore_sparse_tensorsFunction · 0.85
_as_original_typeFunction · 0.85
executing_eagerlyMethod · 0.80
dequeue_up_toMethod · 0.80
dequeue_manyMethod · 0.80

Tested by

no test coverage detected