Python tensorflow.python.ops.data_flow_ops.RandomShuffleQueue() Examples
The following are 20
code examples of tensorflow.python.ops.data_flow_ops.RandomShuffleQueue().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.data_flow_ops
, or try the search function
.
Example #1
Source File: kitti_seg_input.py From KittiSeg with MIT License | 6 votes |
def shuffle_join(tensor_list_list, capacity, min_ad, phase): name = 'shuffel_input' types = _dtypes(tensor_list_list) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_ad, dtypes=types) # Build enque Operations _enqueue_join(queue, tensor_list_list) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_ad), dtypes.float32) * (1. / (capacity - min_ad))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "queue/%s/fraction_over_%d_of_%d_full" % (name + '_' + phase, min_ad, capacity - min_ad)) tf.summary.scalar(summary_name, full) dequeued = queue.dequeue(name='shuffel_deqeue') # dequeued = _deserialize_sparse_tensors(dequeued, sparse_info) return dequeued
Example #2
Source File: kitti_low_input.py From KittiClass with MIT License | 6 votes |
def shuffle_join(tensor_list_list, capacity, min_ad, phase): name = 'shuffel_input' types = _dtypes(tensor_list_list) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_ad, dtypes=types) # Build enque Operations _enqueue_join(queue, tensor_list_list) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_ad), dtypes.float32) * (1. / (capacity - min_ad))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "queue/%s/fraction_over_%d_of_%d_full" % (name + '_' + phase, min_ad, capacity - min_ad)) tf.summary.scalar(summary_name, full) dequeued = queue.dequeue(name='shuffel_deqeue') # dequeued = _deserialize_sparse_tensors(dequeued, sparse_info) return dequeued
Example #3
Source File: kitti_input.py From KittiClass with MIT License | 6 votes |
def shuffle_join(tensor_list_list, capacity, min_ad, phase): name = 'shuffel_input' types = _dtypes(tensor_list_list) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_ad, dtypes=types) # Build enque Operations _enqueue_join(queue, tensor_list_list) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_ad), dtypes.float32) * (1. / (capacity - min_ad))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "queue/%s/fraction_over_%d_of_%d_full" % (name + '_' + phase, min_ad, capacity - min_ad)) tf.summary.scalar(summary_name, full) dequeued = queue.dequeue(name='shuffel_deqeue') # dequeued = _deserialize_sparse_tensors(dequeued, sparse_info) return dequeued
Example #4
Source File: input.py From lambda-packs with MIT License | 5 votes |
def _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): """Helper function for `shuffle_batch` and `maybe_shuffle_batch`.""" tensor_list = _as_tensor_list(tensors) with ops.name_scope(name, "shuffle_batch", list(tensor_list) + [keep_input]) as name: tensor_list = _validate(tensor_list) keep_input = _validate_keep_input(keep_input, enqueue_many) tensor_list, sparse_info = _store_sparse_tensors( tensor_list, enqueue_many, keep_input) types = _dtypes([tensor_list]) shapes = _shapes([tensor_list], shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) return _as_original_type(tensors, dequeued)
Example #5
Source File: input.py From lambda-packs with MIT License | 5 votes |
def _shuffle_batch_join(tensors_list, batch_size, capacity, min_after_dequeue, keep_input, seed=None, enqueue_many=False, shapes=None, allow_smaller_final_batch=False, shared_name=None, name=None): """Helper function for `shuffle_batch_join` and `maybe_shuffle_batch_join`.""" tensor_list_list = _as_tensor_list_list(tensors_list) with ops.name_scope(name, "shuffle_batch_join", _flatten(tensor_list_list) + [keep_input]) as name: tensor_list_list = _validate_join(tensor_list_list) keep_input = _validate_keep_input(keep_input, enqueue_many) tensor_list_list, sparse_info = _store_sparse_tensors_join( tensor_list_list, enqueue_many, keep_input) types = _dtypes(tensor_list_list) shapes = _shapes(tensor_list_list, shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue_join(queue, tensor_list_list, enqueue_many, keep_input) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) # tensors_list was validated to not be empty. return _as_original_type(tensors_list[0], dequeued) # Batching functions ----------------------------------------------------------
Example #6
Source File: input.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _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): """Helper function for `shuffle_batch` and `maybe_shuffle_batch`.""" tensor_list = _as_tensor_list(tensors) with ops.name_scope(name, "shuffle_batch", list(tensor_list) + [keep_input]) as name: tensor_list = _validate(tensor_list) keep_input = _validate_tensor_or_none(keep_input) tensor_list, sparse_info = _store_sparse_tensors( tensor_list, enqueue_many, keep_input) types = _dtypes([tensor_list]) shapes = _shapes([tensor_list], shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) return _as_original_type(tensors, dequeued)
Example #7
Source File: input.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _shuffle_batch_join(tensors_list, batch_size, capacity, min_after_dequeue, keep_input, seed=None, enqueue_many=False, shapes=None, allow_smaller_final_batch=False, shared_name=None, name=None): """Helper function for `shuffle_batch_join` and `maybe_shuffle_batch_join`.""" tensor_list_list = _as_tensor_list_list(tensors_list) with ops.name_scope(name, "shuffle_batch_join", _flatten(tensor_list_list) + [keep_input]) as name: tensor_list_list = _validate_join(tensor_list_list) keep_input = _validate_tensor_or_none(keep_input) tensor_list_list, sparse_info = _store_sparse_tensors_join( tensor_list_list, enqueue_many, keep_input) types = _dtypes(tensor_list_list) shapes = _shapes(tensor_list_list, shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue_join(queue, tensor_list_list, enqueue_many, keep_input) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) # tensors_list was validated to not be empty. return _as_original_type(tensors_list[0], dequeued) # Batching functions ----------------------------------------------------------
Example #8
Source File: parallel_reader_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testRandomShuffleQueue(self): shared_queue = data_flow_ops.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[dtypes_lib.string, dtypes_lib.string]) self._verify_all_data_sources_read(shared_queue)
Example #9
Source File: parallel_reader_test.py From keras-lambda with MIT License | 5 votes |
def testRandomShuffleQueue(self): shared_queue = data_flow_ops.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[dtypes_lib.string, dtypes_lib.string]) self._verify_all_data_sources_read(shared_queue)
Example #10
Source File: parallel_reader_test.py From tf-slim with Apache License 2.0 | 5 votes |
def testRandomShuffleQueue(self): shared_queue = data_flow_ops.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[dtypes_lib.string, dtypes_lib.string]) self._verify_all_data_sources_read(shared_queue)
Example #11
Source File: parallel_reader_test.py From tf-slim with Apache License 2.0 | 5 votes |
def testReadUpToFromRandomShuffleQueue(self): shared_queue = data_flow_ops.RandomShuffleQueue( capacity=55, min_after_dequeue=28, dtypes=[dtypes_lib.string, dtypes_lib.string], shapes=[[], []]) self._verify_read_up_to_out(shared_queue)
Example #12
Source File: input.py From keras-lambda with MIT License | 5 votes |
def _shuffle_batch_join(tensors_list, batch_size, capacity, min_after_dequeue, keep_input, seed=None, enqueue_many=False, shapes=None, allow_smaller_final_batch=False, shared_name=None, name=None): """Helper function for `shuffle_batch_join` and `maybe_shuffle_batch_join`.""" tensor_list_list = _as_tensor_list_list(tensors_list) with ops.name_scope(name, "shuffle_batch_join", _flatten(tensor_list_list) + [keep_input]) as name: tensor_list_list = _validate_join(tensor_list_list) keep_input = _validate_tensor_or_none(keep_input) tensor_list_list, sparse_info = _store_sparse_tensors_join( tensor_list_list, enqueue_many, keep_input) types = _dtypes(tensor_list_list) shapes = _shapes(tensor_list_list, shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue_join(queue, tensor_list_list, enqueue_many, keep_input) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) # tensors_list was validated to not be empty. return _as_original_type(tensors_list[0], dequeued) # Batching functions ----------------------------------------------------------
Example #13
Source File: input.py From keras-lambda with MIT License | 5 votes |
def _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): """Helper function for `shuffle_batch` and `maybe_shuffle_batch`.""" tensor_list = _as_tensor_list(tensors) with ops.name_scope(name, "shuffle_batch", list(tensor_list) + [keep_input]) as name: tensor_list = _validate(tensor_list) keep_input = _validate_tensor_or_none(keep_input) tensor_list, sparse_info = _store_sparse_tensors( tensor_list, enqueue_many, keep_input) types = _dtypes([tensor_list]) shapes = _shapes([tensor_list], shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input) full = (math_ops.cast(math_ops.maximum(0, queue.size() - min_after_dequeue), dtypes.float32) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) return _as_original_type(tensors, dequeued)
Example #14
Source File: input.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _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): """Helper function for `shuffle_batch` and `maybe_shuffle_batch`.""" tensor_list = _as_tensor_list(tensors) with ops.name_scope(name, "shuffle_batch", list(tensor_list) + [keep_input]) as name: if capacity <= min_after_dequeue: raise ValueError("capacity %d must be bigger than min_after_dequeue %d." % (capacity, min_after_dequeue)) tensor_list = _validate(tensor_list) keep_input = _validate_keep_input(keep_input, enqueue_many) tensor_list, sparse_info = _store_sparse_tensors( tensor_list, enqueue_many, keep_input) types = _dtypes([tensor_list]) shapes = _shapes([tensor_list], shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input) full = (math_ops.to_float( math_ops.maximum(0, queue.size() - min_after_dequeue)) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) return _as_original_type(tensors, dequeued)
Example #15
Source File: input.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _shuffle_batch_join(tensors_list, batch_size, capacity, min_after_dequeue, keep_input, seed=None, enqueue_many=False, shapes=None, allow_smaller_final_batch=False, shared_name=None, name=None): """Helper function for `shuffle_batch_join` and `maybe_shuffle_batch_join`.""" tensor_list_list = _as_tensor_list_list(tensors_list) with ops.name_scope(name, "shuffle_batch_join", _flatten(tensor_list_list) + [keep_input]) as name: tensor_list_list = _validate_join(tensor_list_list) keep_input = _validate_keep_input(keep_input, enqueue_many) tensor_list_list, sparse_info = _store_sparse_tensors_join( tensor_list_list, enqueue_many, keep_input) types = _dtypes(tensor_list_list) shapes = _shapes(tensor_list_list, shapes, enqueue_many) queue = data_flow_ops.RandomShuffleQueue( capacity=capacity, min_after_dequeue=min_after_dequeue, seed=seed, dtypes=types, shapes=shapes, shared_name=shared_name) _enqueue_join(queue, tensor_list_list, enqueue_many, keep_input) full = (math_ops.to_float( math_ops.maximum(0, queue.size() - min_after_dequeue)) * (1. / (capacity - min_after_dequeue))) # Note that name contains a '/' at the end so we intentionally do not place # a '/' after %s below. summary_name = ( "fraction_over_%d_of_%d_full" % (min_after_dequeue, capacity - min_after_dequeue)) summary.scalar(summary_name, full) if allow_smaller_final_batch: dequeued = queue.dequeue_up_to(batch_size, name=name) else: dequeued = queue.dequeue_many(batch_size, name=name) dequeued = _restore_sparse_tensors(dequeued, sparse_info) # tensors_list was validated to not be empty. return _as_original_type(tensors_list[0], dequeued) # Batching functions ----------------------------------------------------------
Example #16
Source File: parallel_reader.py From keras-lambda with MIT License | 4 votes |
def __init__(self, reader_class, common_queue, num_readers=4, reader_kwargs=None): """ParallelReader creates num_readers instances of the reader_class. Each instance is created by calling the `reader_class` function passing the arguments specified in `reader_kwargs` as in: reader_class(**read_kwargs) When you read from a ParallelReader, with its `read()` method, you just dequeue examples from the `common_queue`. The readers will read different files in parallel, asynchronously enqueueing their output into `common_queue`. The `common_queue.dtypes` must be [tf.string, tf.string] Because each reader can read from a different file, the examples in the `common_queue` could be from different files. Due to the asynchronous reading there is no guarantee that all the readers will read the same number of examples. If the `common_queue` is a shuffling queue, then the examples are shuffled. Usage: common_queue = tf.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(tf.TFRecordReader, common_queue) common_queue = tf.FIFOQueue( capacity=256, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(readers, common_queue, num_readers=2) Args: reader_class: one of the io_ops.ReaderBase subclasses ex: TFRecordReader common_queue: a Queue to hold (key, value pairs) with `dtypes` equal to [tf.string, tf.string]. Must be one of the data_flow_ops.Queues instances, ex. `tf.FIFOQueue()`, `tf.RandomShuffleQueue()`, ... num_readers: a integer, number of instances of reader_class to create. reader_kwargs: an optional dict of kwargs to create the readers. Raises: TypeError: if `common_queue.dtypes` is not [tf.string, tf.string]. """ if len(common_queue.dtypes) != 2: raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') for dtype in common_queue.dtypes: if not dtype.is_compatible_with(tf_dtypes.string): raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') reader_kwargs = reader_kwargs or {} self._readers = [reader_class(**reader_kwargs) for _ in range(num_readers)] self._common_queue = common_queue
Example #17
Source File: parallel_reader.py From deep_image_model with Apache License 2.0 | 4 votes |
def __init__(self, reader_class, common_queue, num_readers=4, reader_kwargs=None): """ParallelReader creates num_readers instances of the reader_class. Each instance is created by calling the `reader_class` function passing the arguments specified in `reader_kwargs` as in: reader_class(**read_kwargs) When you read from a ParallelReader, with its `read()` method, you just dequeue examples from the `common_queue`. The readers will read different files in parallel, asynchronously enqueueing their output into `common_queue`. The `common_queue.dtypes` must be [tf.string, tf.string] Because each reader can read from a different file, the examples in the `common_queue` could be from different files. Due to the asynchronous reading there is no guarantee that all the readers will read the same number of examples. If the `common_queue` is a shuffling queue, then the examples are shuffled. Usage: common_queue = tf.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(tf.TFRecordReader, common_queue) common_queue = tf.FIFOQueue( capacity=256, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(readers, common_queue, num_readers=2) Args: reader_class: one of the io_ops.ReaderBase subclasses ex: TFRecordReader common_queue: a Queue to hold (key, value pairs) with `dtypes` equal to [tf.string, tf.string]. Must be one of the data_flow_ops.Queues instances, ex. `tf.FIFOQueue()`, `tf.RandomShuffleQueue()`, ... num_readers: a integer, number of instances of reader_class to create. reader_kwargs: an optional dict of kwargs to create the readers. Raises: TypeError: if `common_queue.dtypes` is not [tf.string, tf.string]. """ if len(common_queue.dtypes) != 2: raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') for dtype in common_queue.dtypes: if not dtype.is_compatible_with(tf_dtypes.string): raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') reader_kwargs = reader_kwargs or {} self._readers = [reader_class(**reader_kwargs) for _ in range(num_readers)] self._common_queue = common_queue
Example #18
Source File: parallel_reader.py From tf-slim with Apache License 2.0 | 4 votes |
def __init__(self, reader_class, common_queue, num_readers=4, reader_kwargs=None): """ParallelReader creates num_readers instances of the reader_class. Each instance is created by calling the `reader_class` function passing the arguments specified in `reader_kwargs` as in: reader_class(**read_kwargs) When you read from a ParallelReader, with its `read()` method, you just dequeue examples from the `common_queue`. The readers will read different files in parallel, asynchronously enqueueing their output into `common_queue`. The `common_queue.dtypes` must be [tf.string, tf.string] Because each reader can read from a different file, the examples in the `common_queue` could be from different files. Due to the asynchronous reading there is no guarantee that all the readers will read the same number of examples. If the `common_queue` is a shuffling queue, then the examples are shuffled. Usage: common_queue = tf.queue.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(tf.compat.v1.TFRecordReader, common_queue) common_queue = tf.queue.FIFOQueue( capacity=256, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(readers, common_queue, num_readers=2) Args: reader_class: one of the io_ops.ReaderBase subclasses ex: TFRecordReader common_queue: a Queue to hold (key, value pairs) with `dtypes` equal to [tf.string, tf.string]. Must be one of the data_flow_ops.Queues instances, ex. `tf.queue.FIFOQueue()`, `tf.queue.RandomShuffleQueue()`, ... num_readers: a integer, number of instances of reader_class to create. reader_kwargs: an optional dict of kwargs to create the readers. Raises: TypeError: if `common_queue.dtypes` is not [tf.string, tf.string]. """ if len(common_queue.dtypes) != 2: raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') for dtype in common_queue.dtypes: if not dtype.is_compatible_with(tf_dtypes.string): raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') reader_kwargs = reader_kwargs or {} self._readers = [reader_class(**reader_kwargs) for _ in range(num_readers)] self._common_queue = common_queue
Example #19
Source File: parallel_reader.py From auto-alt-text-lambda-api with MIT License | 4 votes |
def __init__(self, reader_class, common_queue, num_readers=4, reader_kwargs=None): """ParallelReader creates num_readers instances of the reader_class. Each instance is created by calling the `reader_class` function passing the arguments specified in `reader_kwargs` as in: reader_class(**read_kwargs) When you read from a ParallelReader, with its `read()` method, you just dequeue examples from the `common_queue`. The readers will read different files in parallel, asynchronously enqueueing their output into `common_queue`. The `common_queue.dtypes` must be [tf.string, tf.string] Because each reader can read from a different file, the examples in the `common_queue` could be from different files. Due to the asynchronous reading there is no guarantee that all the readers will read the same number of examples. If the `common_queue` is a shuffling queue, then the examples are shuffled. Usage: common_queue = tf.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(tf.TFRecordReader, common_queue) common_queue = tf.FIFOQueue( capacity=256, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(readers, common_queue, num_readers=2) Args: reader_class: one of the io_ops.ReaderBase subclasses ex: TFRecordReader common_queue: a Queue to hold (key, value pairs) with `dtypes` equal to [tf.string, tf.string]. Must be one of the data_flow_ops.Queues instances, ex. `tf.FIFOQueue()`, `tf.RandomShuffleQueue()`, ... num_readers: a integer, number of instances of reader_class to create. reader_kwargs: an optional dict of kwargs to create the readers. Raises: TypeError: if `common_queue.dtypes` is not [tf.string, tf.string]. """ if len(common_queue.dtypes) != 2: raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') for dtype in common_queue.dtypes: if not dtype.is_compatible_with(tf_dtypes.string): raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') reader_kwargs = reader_kwargs or {} self._readers = [reader_class(**reader_kwargs) for _ in range(num_readers)] self._common_queue = common_queue
Example #20
Source File: parallel_reader.py From lambda-packs with MIT License | 4 votes |
def __init__(self, reader_class, common_queue, num_readers=4, reader_kwargs=None): """ParallelReader creates num_readers instances of the reader_class. Each instance is created by calling the `reader_class` function passing the arguments specified in `reader_kwargs` as in: reader_class(**read_kwargs) When you read from a ParallelReader, with its `read()` method, you just dequeue examples from the `common_queue`. The readers will read different files in parallel, asynchronously enqueueing their output into `common_queue`. The `common_queue.dtypes` must be [tf.string, tf.string] Because each reader can read from a different file, the examples in the `common_queue` could be from different files. Due to the asynchronous reading there is no guarantee that all the readers will read the same number of examples. If the `common_queue` is a shuffling queue, then the examples are shuffled. Usage: common_queue = tf.RandomShuffleQueue( capacity=256, min_after_dequeue=128, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(tf.TFRecordReader, common_queue) common_queue = tf.FIFOQueue( capacity=256, dtypes=[tf.string, tf.string]) p_reader = ParallelReader(readers, common_queue, num_readers=2) Args: reader_class: one of the io_ops.ReaderBase subclasses ex: TFRecordReader common_queue: a Queue to hold (key, value pairs) with `dtypes` equal to [tf.string, tf.string]. Must be one of the data_flow_ops.Queues instances, ex. `tf.FIFOQueue()`, `tf.RandomShuffleQueue()`, ... num_readers: a integer, number of instances of reader_class to create. reader_kwargs: an optional dict of kwargs to create the readers. Raises: TypeError: if `common_queue.dtypes` is not [tf.string, tf.string]. """ if len(common_queue.dtypes) != 2: raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') for dtype in common_queue.dtypes: if not dtype.is_compatible_with(tf_dtypes.string): raise TypeError('common_queue.dtypes must be [tf.string, tf.string]') reader_kwargs = reader_kwargs or {} self._readers = [reader_class(**reader_kwargs) for _ in range(num_readers)] self._common_queue = common_queue