本文整理汇总了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
示例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,)
示例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)
示例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]
}
示例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.')
示例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.
示例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
示例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
示例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
示例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()
示例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()
示例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)