Beispiel #1
0
    def read(self, queue, name=None):
        """Returns the next record (key, value) pair produced by a reader.

    Will dequeue a work unit from queue if necessary (e.g. when the
    Reader needs to start reading from a new file since it has
    finished with the previous file).

    Args:
      queue: A Queue or a mutable string Tensor representing a handle
        to a Queue, with string work items.
      name: A name for the operation (optional).

    Returns:
      A tuple of Tensors (key, value).
      key: A string scalar Tensor.
      value: A string scalar Tensor.
    """
        if isinstance(queue, ops.Tensor):
            queue_ref = queue
        else:
            queue_ref = queue.queue_ref
        if self._reader_ref.dtype == dtypes.resource:
            return gen_io_ops._reader_read_v2(self._reader_ref,
                                              queue_ref,
                                              name=name)
        else:
            # For compatibility with pre-resource queues, create a ref(string) tensor
            # which can be looked up as the same queue by a resource manager.
            old_queue_op = gen_data_flow_ops._fake_queue(queue_ref)
            return gen_io_ops._reader_read(self._reader_ref,
                                           old_queue_op,
                                           name=name)
Beispiel #2
0
  def read(self, queue, name=None):
    """Returns the next record (key, value pair) produced by a reader.

    Will dequeue a work unit from queue if necessary (e.g. when the
    Reader needs to start reading from a new file since it has
    finished with the previous file).

    Args:
      queue: A Queue or a mutable string Tensor representing a handle
        to a Queue, with string work items.
      name: A name for the operation (optional).

    Returns:
      A tuple of Tensors (key, value).
      key: A string scalar Tensor.
      value: A string scalar Tensor.
    """
    if isinstance(queue, ops.Tensor):
      queue_ref = queue
    else:
      queue_ref = queue.queue_ref
    if self._reader_ref.dtype == dtypes.resource:
      return gen_io_ops._reader_read_v2(self._reader_ref, queue_ref, name=name)
    else:
      # For compatibility with pre-resource queues, create a ref(string) tensor
      # which can be looked up as the same queue by a resource manager.
      old_queue_op = gen_data_flow_ops._fake_queue(queue_ref)
      return gen_io_ops._reader_read(self._reader_ref, old_queue_op, name=name)
Beispiel #3
0
    def read_up_to(
            self,
            queue,
            num_records,  # pylint: disable=invalid-name
            name=None):
        """Returns up to num_records (key, value) pairs produced by a reader.

    Will dequeue a work unit from queue if necessary (e.g., when the
    Reader needs to start reading from a new file since it has
    finished with the previous file).
    It may return less than num_records even before the last batch.

    Args:
      queue: A Queue or a mutable string Tensor representing a handle
        to a Queue, with string work items.
      num_records: Number of records to read.
      name: A name for the operation (optional).

    Returns:
      A tuple of Tensors (keys, values).
      keys: A 1-D string Tensor.
      values: A 1-D string Tensor.
    """
        if isinstance(queue, ops.Tensor):
            queue_ref = queue
        else:
            queue_ref = queue.queue_ref
        if self._reader_ref.dtype == dtypes.resource:
            return gen_io_ops._reader_read_up_to_v2(self._reader_ref,
                                                    queue_ref,
                                                    num_records,
                                                    name=name)
        else:
            # For compatibility with pre-resource queues, create a ref(string) tensor
            # which can be looked up as the same queue by a resource manager.
            old_queue_op = gen_data_flow_ops._fake_queue(queue_ref)
            return gen_io_ops._reader_read_up_to(self._reader_ref,
                                                 old_queue_op,
                                                 num_records,
                                                 name=name)
Beispiel #4
0
  def read_up_to(self, queue, num_records,  # pylint: disable=invalid-name
                 name=None):
    """Returns up to num_records (key, value pairs) produced by a reader.

    Will dequeue a work unit from queue if necessary (e.g., when the
    Reader needs to start reading from a new file since it has
    finished with the previous file).
    It may return less than num_records even before the last batch.

    Args:
      queue: A Queue or a mutable string Tensor representing a handle
        to a Queue, with string work items.
      num_records: Number of records to read.
      name: A name for the operation (optional).

    Returns:
      A tuple of Tensors (keys, values).
      keys: A 1-D string Tensor.
      values: A 1-D string Tensor.
    """
    if isinstance(queue, ops.Tensor):
      queue_ref = queue
    else:
      queue_ref = queue.queue_ref
    if self._reader_ref.dtype == dtypes.resource:
      return gen_io_ops._reader_read_up_to_v2(self._reader_ref,
                                              queue_ref,
                                              num_records,
                                              name=name)
    else:
      # For compatibility with pre-resource queues, create a ref(string) tensor
      # which can be looked up as the same queue by a resource manager.
      old_queue_op = gen_data_flow_ops._fake_queue(queue_ref)
      return gen_io_ops._reader_read_up_to_v2(self._reader_ref,
                                              old_queue_op,
                                              num_records,
                                              name=name)