本文整理汇总了Python中tensorflow.python.framework.errors.raise_exception_on_not_ok_status方法的典型用法代码示例。如果您正苦于以下问题:Python errors.raise_exception_on_not_ok_status方法的具体用法?Python errors.raise_exception_on_not_ok_status怎么用?Python errors.raise_exception_on_not_ok_status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.framework.errors
的用法示例。
在下文中一共展示了errors.raise_exception_on_not_ok_status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _extend_graph
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def _extend_graph(self):
# Ensure any changes to the graph are reflected in the runtime.
with self._extend_lock:
if self._graph.version > self._current_version:
# pylint: disable=protected-access
graph_def, self._current_version = self._graph._as_graph_def(
from_version=self._current_version,
add_shapes=self._add_shapes)
# pylint: enable=protected-access
with errors.raise_exception_on_not_ok_status() as status:
tf_session.TF_ExtendGraph(
self._session, graph_def.SerializeToString(), status)
self._opened = True
# The threshold to run garbage collection to delete dead tensors.
示例2: read
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def read(self, n=-1):
"""Returns the contents of a file as a string.
Starts reading from current position in file.
Args:
n: Read 'n' bytes if n != -1. If n = -1, reads to end of file.
Returns:
'n' bytes of the file (or whole file) in bytes mode or 'n' bytes of the
string if in string (regular) mode.
"""
self._preread_check()
with errors.raise_exception_on_not_ok_status() as status:
if n == -1:
length = self.size() - self.tell()
else:
length = n
return self._prepare_value(
pywrap_tensorflow.ReadFromStream(self._read_buf, length, status))
示例3: file_exists
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def file_exists(filename):
"""Determines whether a path exists or not.
Args:
filename: string, a path
Returns:
True if the path exists, whether its a file or a directory.
False if the path does not exist and there are no filesystem errors.
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API.
"""
try:
with errors.raise_exception_on_not_ok_status() as status:
pywrap_tensorflow.FileExists(compat.as_bytes(filename), status)
except errors.NotFoundError:
return False
return True
示例4: list_directory
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def list_directory(dirname):
"""Returns a list of entries contained within a directory.
The list is in arbitrary order. It does not contain the special entries "."
and "..".
Args:
dirname: string, path to a directory
Returns:
[filename1, filename2, ... filenameN] as strings
Raises:
errors.NotFoundError if directory doesn't exist
"""
if not is_directory(dirname):
raise errors.NotFoundError(None, None, "Could not find directory")
with errors.raise_exception_on_not_ok_status() as status:
# Convert each element to string, since the return values of the
# vector of string should be interpreted as strings, not bytes.
return [
compat.as_str_any(filename)
for filename in pywrap_tensorflow.GetChildren(
compat.as_bytes(dirname), status)
]
示例5: read
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def read(self, n=-1):
"""Returns the contents of a file as a string.
Starts reading from current position in file.
Args:
n: Read 'n' bytes if n != -1. If n = -1, reads to end of file.
Returns:
'n' bytes of the file (or whole file) requested as a string.
"""
self._preread_check()
with errors.raise_exception_on_not_ok_status() as status:
if n == -1:
length = self.size() - self.tell()
else:
length = n
return pywrap_tensorflow.ReadFromStream(self._read_buf, length, status)
示例6: get_matching_files
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def get_matching_files(filename):
"""Returns a list of files that match the given pattern.
Args:
filename: string, the pattern
Returns:
Returns a list of strings containing filenames that match the given pattern.
Raises:
errors.OpError: If there are filesystem / directory listing errors.
"""
with errors.raise_exception_on_not_ok_status() as status:
# Convert each element to string, since the return values of the
# vector of string should be interpreted as strings, not bytes.
return [compat.as_str_any(matching_filename)
for matching_filename in pywrap_tensorflow.GetMatchingFiles(
compat.as_bytes(filename), status)]
示例7: Load
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [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)
示例8: close
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def close(self):
"""Closes this session.
Calling this method frees all resources associated with the session.
Raises:
tf.errors.OpError: Or one of its subclasses if an error occurs while
closing the TensorFlow session.
"""
if self._created_with_new_api:
if self._session and not self._closed:
self._closed = True
with errors.raise_exception_on_not_ok_status() as status:
tf_session.TF_CloseSession(self._session, status)
else:
with self._extend_lock:
if self._opened and not self._closed:
self._closed = True
with errors.raise_exception_on_not_ok_status() as status:
tf_session.TF_CloseDeprecatedSession(self._session, status)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:23,代码来源:session.py
示例9: _extend_graph
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def _extend_graph(self):
# Nothing to do if we're using the new session interface
# TODO(skyewm): remove this function altogether eventually
if self._created_with_new_api: return
# Ensure any changes to the graph are reflected in the runtime.
with self._extend_lock:
if self._graph.version > self._current_version:
# pylint: disable=protected-access
graph_def, self._current_version = self._graph._as_graph_def(
from_version=self._current_version,
add_shapes=self._add_shapes)
# pylint: enable=protected-access
with errors.raise_exception_on_not_ok_status() as status:
tf_session.TF_ExtendGraph(
self._session, graph_def.SerializeToString(), status)
self._opened = True
# The threshold to run garbage collection to delete dead tensors.
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:22,代码来源:session.py
示例10: _initialize_handle_and_devices
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def _initialize_handle_and_devices(self):
"""Initialize handle and devices."""
with self._initialize_lock:
if self._context_handle is not None:
return
assert self._context_devices is None
opts = pywrap_tensorflow.TF_NewSessionOptions(
target=compat.as_bytes(""), config=self._config)
with errors.raise_exception_on_not_ok_status() as status:
self._context_handle = pywrap_tensorflow.TFE_NewContext(opts, status)
pywrap_tensorflow.TF_DeleteSessionOptions(opts)
# Store list of devices
self._context_devices = []
with errors.raise_exception_on_not_ok_status() as status:
device_list = pywrap_tensorflow.TFE_ContextListDevices(
self._context_handle, status)
try:
for i in range(pywrap_tensorflow.TF_DeviceListCount(device_list)):
with errors.raise_exception_on_not_ok_status() as status:
dev_name = pywrap_tensorflow.TF_DeviceListName(
device_list, i, status)
self._context_devices.append(pydev.canonical_name(dev_name))
finally:
pywrap_tensorflow.TF_DeleteDeviceList(device_list)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:26,代码来源:context.py
示例11: add_function_def
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def add_function_def(self, fdef):
"""Add a function definition to the context.
Once added, the function (identified by its name) can be executed like any
other operation.
Args:
fdef: A FunctionDef protocol buffer message.
"""
fdef_string = fdef.SerializeToString()
with errors.raise_exception_on_not_ok_status() as status:
pywrap_tensorflow.TFE_ContextAddFunctionDef(
self._handle, # pylint: disable=protected-access
fdef_string,
len(fdef_string),
status)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:18,代码来源:context.py
示例12: NewCheckpointReader
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def NewCheckpointReader(filepattern):
from tensorflow.python.framework import errors
with errors.raise_exception_on_not_ok_status() as status:
from tensorflow.python.util import compat
return CheckpointReader(compat.as_bytes(filepattern), status)
示例13: get_tensor
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def get_tensor(self, tensor_str):
from tensorflow.python.framework import errors
with errors.raise_exception_on_not_ok_status() as status:
from tensorflow.python.util import compat
return CheckpointReader_GetTensor(self, compat.as_bytes(tensor_str),
status)
示例14: TF_NewSessionOptions
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def TF_NewSessionOptions(target=None, config=None):
# NOTE: target and config are validated in the session constructor.
opts = _TF_NewSessionOptions()
if target is not None:
_TF_SetTarget(opts, target)
if config is not None:
from tensorflow.python.framework import errors
with errors.raise_exception_on_not_ok_status() as status:
config_str = config.SerializeToString()
_TF_SetConfig(opts, config_str, status)
return opts
示例15: TF_Reset
# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import raise_exception_on_not_ok_status [as 别名]
def TF_Reset(target, containers=None, config=None):
from tensorflow.python.framework import errors
opts = TF_NewSessionOptions(target=target, config=config)
try:
with errors.raise_exception_on_not_ok_status() as status:
TF_Reset_wrapper(opts, containers, status)
finally:
TF_DeleteSessionOptions(opts)