當前位置: 首頁>>代碼示例>>Python>>正文


Python errors.OutOfRangeError方法代碼示例

本文整理匯總了Python中tensorflow.python.framework.errors.OutOfRangeError方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.OutOfRangeError方法的具體用法?Python errors.OutOfRangeError怎麽用?Python errors.OutOfRangeError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.framework.errors的用法示例。


在下文中一共展示了errors.OutOfRangeError方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __call__(self):
    if self._num_epochs and self._epoch >= self._num_epochs:
      raise errors.OutOfRangeError(None, None,
                                   "Already emitted %s epochs." % self._epoch)
    list_dict = {}
    list_dict_size = 0
    while list_dict_size < self._batch_size:
      try:
        data_row = next(self._iterator)
      except StopIteration:
        self._epoch += 1
        self._iterator = self._generator_function()
        data_row = next(self._iterator)
      for index, key in enumerate(self._keys):
        if key not in data_row.keys():
          raise KeyError("key mismatch between dicts emitted by GenFun"
                         "Expected {} keys; got {}".format(
                             self._keys, data_row.keys()))
        list_dict.setdefault(self._col_placeholders[index],
                             list()).append(data_row[key])
        list_dict_size += 1
    feed_dict = {key: np.asarray(item) for key, item in list(list_dict.items())}
    return feed_dict 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:25,代碼來源:feeding_functions.py

示例2: _init_from_proto

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def _init_from_proto(self, queue_runner_def, import_scope=None):
    """Create a QueueRunner from `QueueRunnerDef`.

    Args:
      queue_runner_def: Optional `QueueRunnerDef` protocol buffer.
      import_scope: Optional `string`. Name scope to add.
    """
    assert isinstance(queue_runner_def, queue_runner_pb2.QueueRunnerDef)
    g = ops.get_default_graph()
    self._queue = g.as_graph_element(
        ops.prepend_name_scope(queue_runner_def.queue_name, import_scope))
    self._enqueue_ops = [g.as_graph_element(
        ops.prepend_name_scope(op, import_scope))
                         for op in queue_runner_def.enqueue_op_name]
    self._close_op = g.as_graph_element(ops.prepend_name_scope(
        queue_runner_def.close_op_name, import_scope))
    self._cancel_op = g.as_graph_element(ops.prepend_name_scope(
        queue_runner_def.cancel_op_name, import_scope))
    self._queue_closed_exception_types = tuple(
        errors.exception_type_from_error_code(code)
        for code in queue_runner_def.queue_closed_exception_types)
    # Legacy support for old QueueRunnerDefs created before this field
    # was added.
    if not self._queue_closed_exception_types:
      self._queue_closed_exception_types = (errors.OutOfRangeError,) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:27,代碼來源:queue_runner_impl.py

示例3: Load

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def Load(self):
    """Loads all new values from disk.

    Calling Load multiple times in a row will not 'drop' events as long as the
    return value is not iterated over.

    Yields:
      All values that were written to disk that have not been yielded yet.
    """
    while True:
      try:
        with errors.raise_exception_on_not_ok_status() as status:
          self._reader.GetNext(status)
      except (errors.DataLossError, errors.OutOfRangeError):
        # We ignore partial read exceptions, because a record may be truncated.
        # PyRecordReader holds the offset prior to the failed read, so retrying
        # will succeed.
        break
      event = event_pb2.Event()
      event.ParseFromString(self._reader.record())
      yield event
    logging.debug('No more events in %s', self._file_path) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:event_file_loader.py

示例4: __call__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __call__(self):
    if self._num_epochs and self._epoch >= self._num_epochs:
      raise errors.OutOfRangeError(None, None,
                                   "Already emitted %s epochs." % self._epoch)

    integer_indexes = [
        j % self._max for j in range(self._trav, self._trav + self._batch_size)
    ]

    if self._epoch_end in integer_indexes:
      # after this batch we will have processed self._epoch epochs, possibly
      # overshooting a bit to fill out a batch.
      self._epoch += 1

    self._trav = (integer_indexes[-1] + 1) % self._max
    return {
        self._placeholders[0]: integer_indexes,
        self._placeholders[1]: self._array[integer_indexes]
    } 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:21,代碼來源:feeding_functions.py

示例5: after_run

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def after_run(self, run_context, run_values):
    _ = run_context
    scalar_stopping_signal = run_values.results
    if _StopSignals.should_stop(scalar_stopping_signal):
      # NOTE(xiejw): In prediction, stopping signals are inserted for each
      # batch. And we append one more batch to signal the system it should stop.
      # The data flow might look like
      #
      #  batch   0: images, labels, stop = 0  (user provided)
      #  batch   1: images, labels, stop = 0  (user provided)
      #  ...
      #  batch  99: images, labels, stop = 0  (user provided)
      #  batch 100: images, labels, stop = 1  (TPUEstimator appended)
      #
      # where the final batch (id = 100) is appended by TPUEstimator, so we
      # should drop it before returning the predictions to user.
      # To achieve that, we throw the OutOfRangeError in after_run. Once
      # Monitored Session sees this error in SessionRunHook.after_run, the
      # "current" prediction, i.e., batch with id=100, will be discarded
      # immediately
      raise errors.OutOfRangeError(None, None, 'Stopped by stopping signal.') 
開發者ID:ymcui,項目名稱:Chinese-XLNet,代碼行數:23,代碼來源:tpu_estimator.py

示例6: __init__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __init__(self, queues, enqueue_ops):
    close_op = tf.group(* [q.close() for q in queues])
    cancel_op = tf.group(
        * [q.close(cancel_pending_enqueues=True) for q in queues])
    queue_closed_exception_types = (errors.OutOfRangeError,)

    enqueue_op = tf.group(*enqueue_ops, name="multi_enqueue")

    super(MultiQueueRunner, self).__init__(
        queues[0],
        enqueue_ops=[enqueue_op],
        close_op=close_op,
        cancel_op=cancel_op,
        queue_closed_exception_types=queue_closed_exception_types)


# This function is not elegant, but I tried so many other ways to get this to
# work and this is the only one that ended up not incuring significant overhead
# or obscure tensorflow bugs. 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:21,代碼來源:utils.py

示例7: __call__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __call__(self):
    if self._num_epochs and self._epoch >= self._num_epochs:
      raise errors.OutOfRangeError(None, None,
                                   "Already emitted %s epochs." % self._epoch)

    integer_indexes = [j % self._max
                       for j in range(self._trav, self._trav + self._batch_size)
                      ]

    if self._epoch_end in integer_indexes:
      # after this batch we will have processed self._epoch epochs, possibly
      # overshooting a bit to fill out a batch.
      self._epoch += 1

    self._trav = (integer_indexes[-1] + 1) % self._max
    feed_dict = {self._index_placeholder: integer_indexes}
    cols = [column[integer_indexes]
            for column in self._ordered_dict_of_arrays.values()]
    feed_dict.update(dict(zip(self._col_placeholders, cols)))
    return feed_dict 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:22,代碼來源:feeding_functions.py

示例8: __init__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __init__(self, queue=None, enqueue_ops=None, close_op=None,
               cancel_op=None, feed_fns=None,
               queue_closed_exception_types=None):
    """Initialize the queue runner.

    For further documentation, see `queue_runner.py`. Note that
    `FeedingQueueRunner` does not support construction from protobuffer nor
    serialization to protobuffer.

    Args:
      queue: A `Queue`.
      enqueue_ops: List of enqueue ops to run in threads later.
      close_op: Op to close the queue. Pending enqueue ops are preserved.
      cancel_op: Op to close the queue and cancel pending enqueue ops.
      feed_fns: a list of functions that return a dictionary mapping fed
        `Tensor`s to values. Must be the same length as `enqueue_ops`.
      queue_closed_exception_types: Optional tuple of Exception types that
        indicate that the queue has been closed when raised during an enqueue
        operation.  Defaults to
        `(tf.errors.OutOfRangeError, tf.errors.CancelledError)`.

    Raises:
      ValueError: `feed_fns` is not `None` and has different length than
        `enqueue_ops`.
    """
    if queue_closed_exception_types is None:
      queue_closed_exception_types = (
          errors.OutOfRangeError, errors.CancelledError)
    super(_FeedingQueueRunner, self).__init__(
        queue, enqueue_ops, close_op,
        cancel_op, queue_closed_exception_types=queue_closed_exception_types)
    if feed_fns is None:
      self._feed_fns = [None for _ in enqueue_ops]
    else:
      if len(feed_fns) != len(enqueue_ops):
        raise ValueError(
            "If feed_fns is not None, it must have the same length as "
            "enqueue_ops.")
      self._feed_fns = feed_fns

  # pylint: disable=broad-except 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:43,代碼來源:feeding_queue_runner.py

示例9: __exit__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __exit__(self, exception_type, exception_value, traceback):
    if exception_type in [errors.OutOfRangeError, StopIteration]:
      exception_type = None
    self._close_internal(exception_type)
    # __exit__ should return True to suppress an exception.
    return exception_type is None 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:monitored_session.py

示例10: __init__

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def __init__(self, clean_stop_exception_types=None):
    """Create a new Coordinator.

    Args:
      clean_stop_exception_types: Optional tuple of Exception types that should
        cause a clean stop of the coordinator. If an exception of one of these
        types is reported to `request_stop(ex)` the coordinator will behave as
        if `request_stop(None)` was called.  Defaults to
        `(tf.errors.OutOfRangeError,)` which is used by input queues to signal
        the end of input. When feeding training data from a Python iterator it
        is common to add `StopIteration` to this list.
    """
    if clean_stop_exception_types is None:
      clean_stop_exception_types = (errors.OutOfRangeError,)
    self._clean_stop_exception_types = tuple(clean_stop_exception_types)
    # Protects all attributes.
    self._lock = threading.Lock()
    # Event set when threads must stop.
    self._stop_event = threading.Event()
    # Python exc_info to report.
    # If not None, it should hold the returned value of sys.exc_info(), which is
    # a tuple containing exception (type, value, traceback).
    self._exc_info_to_raise = None
    # True if we have called join() already.
    self._joined = False
    # Set of threads registered for joining when join() is called.  These
    # threads will be joined in addition to the threads passed to the join()
    # call.  It's ok if threads are both registered and passed to the join()
    # call.
    self._registered_threads = set() 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:32,代碼來源:coordinator.py

示例11: tf_record_iterator

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def tf_record_iterator(path, options=None):
  """An iterator that read the records from a TFRecords file.

  Args:
    path: The path to the TFRecords file.
    options: (optional) A TFRecordOptions object.

  Yields:
    Strings.

  Raises:
    IOError: If `path` cannot be opened for reading.
  """
  compression_type = TFRecordOptions.get_compression_type_string(options)
  with errors.raise_exception_on_not_ok_status() as status:
    reader = pywrap_tensorflow.PyRecordReader_New(
        compat.as_bytes(path), 0, compat.as_bytes(compression_type), status)

  if reader is None:
    raise IOError("Could not open %s." % path)
  while True:
    try:
      with errors.raise_exception_on_not_ok_status() as status:
        reader.GetNext(status)
    except errors.OutOfRangeError:
      break
    yield reader.record()
  reader.Close() 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:30,代碼來源:tf_record.py

示例12: _assert_output

# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import OutOfRangeError [as 別名]
def _assert_output(self, expected_list, session, op):
    for element in expected_list:
      self.assertEqual(element, session.run(op))
    with self.assertRaises(errors.OutOfRangeError):
      session.run(op) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:7,代碼來源:input_pipeline_ops_test.py


注:本文中的tensorflow.python.framework.errors.OutOfRangeError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。