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

Function _shuffle_batch

tensorflow/python/training/input.py:835–876  ·  view source on GitHub ↗

Helper function for `shuffle_batch` and `maybe_shuffle_batch`.

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

833
834
835def _shuffle_batch(tensors, batch_size, capacity, min_after_dequeue,
836 keep_input, num_threads=1, seed=None, enqueue_many=False,
837 shapes=None, allow_smaller_final_batch=False,
838 shared_name=None, name=None):
839 """Helper function for `shuffle_batch` and `maybe_shuffle_batch`."""
840 if context.executing_eagerly():
841 raise ValueError(
842 "Input pipelines based on Queues are not supported when eager execution"
843 " is enabled. Please use tf.data to ingest data into your model"
844 " instead.")
845 tensor_list = _as_tensor_list(tensors)
846 with ops.name_scope(name, "shuffle_batch",
847 list(tensor_list) + [keep_input]) as name:
848 if capacity <= min_after_dequeue:
849 raise ValueError("capacity %d must be bigger than min_after_dequeue %d."
850 % (capacity, min_after_dequeue))
851 tensor_list = _validate(tensor_list)
852 keep_input = _validate_keep_input(keep_input, enqueue_many)
853 tensor_list, sparse_info = _store_sparse_tensors(
854 tensor_list, enqueue_many, keep_input)
855 types = _dtypes([tensor_list])
856 shapes = _shapes([tensor_list], shapes, enqueue_many)
857 queue = data_flow_ops.RandomShuffleQueue(
858 capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed,
859 dtypes=types, shapes=shapes, shared_name=shared_name)
860 _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input)
861 full = (math_ops.cast(
862 math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) *
863 (1. / (capacity - min_after_dequeue)))
864 # Note that name contains a '/' at the end so we intentionally do not place
865 # a '/' after %s below.
866 summary_name = (
867 "fraction_over_%d_of_%d_full" %
868 (min_after_dequeue, capacity - min_after_dequeue))
869 summary.scalar(summary_name, full)
870
871 if allow_smaller_final_batch:
872 dequeued = queue.dequeue_up_to(batch_size, name=name)
873 else:
874 dequeued = queue.dequeue_many(batch_size, name=name)
875 dequeued = _restore_sparse_tensors(dequeued, sparse_info)
876 return _as_original_type(tensors, dequeued)
877
878
879def _shuffle_batch_join(tensors_list, batch_size, capacity,

Callers 2

shuffle_batchFunction · 0.85
maybe_shuffle_batchFunction · 0.85

Calls 15

sizeMethod · 0.95
_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
RandomShuffleQueueMethod · 0.80

Tested by

no test coverage detected