本文整理匯總了Python中tensorflow.python.framework.errors.NotFoundError方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.NotFoundError方法的具體用法?Python errors.NotFoundError怎麽用?Python errors.NotFoundError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.framework.errors
的用法示例。
在下文中一共展示了errors.NotFoundError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: file_exists
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [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
示例2: read_file_to_string
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def read_file_to_string(filename, binary_mode=False):
"""Reads the entire contents of a file to a string.
Args:
filename: string, path to a file
binary_mode: whether to open the file in binary mode or not. This changes
the type of the object returned.
Returns:
contents of the file as a string or bytes.
Raises:
errors.OpError: Raises variety of errors that are subtypes e.g.
NotFoundError etc.
"""
if binary_mode:
f = FileIO(filename, mode="rb")
else:
f = FileIO(filename, mode="r")
return f.read()
示例3: list_directory
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [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)
]
示例4: _load_library
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def _load_library(name, op_list=None):
"""Loads a .so file containing the specified operators.
Args:
name: The name of the .so file to load.
op_list: A list of names of operators that the library should have. If None
then the .so file's contents will not be verified.
Raises:
NameError if one of the required ops is missing.
"""
try:
filename = resource_loader.get_path_to_datafile(name)
library = load_library.load_op_library(filename)
for expected_op in (op_list or []):
for lib_op in library.OP_LIST.op:
if lib_op.name == expected_op:
break
else:
raise NameError('Could not find operator %s in dynamic library %s' %
(expected_op, name))
except errors.NotFoundError:
logging.warning('%s file could not be loaded.', name)
示例5: delete_file
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def delete_file(filename):
"""Deletes the file located at 'filename'.
Args:
filename: string, a filename
Raises:
errors.OpError: Propagates any errors reported by the FileSystem API. E.g.,
NotFoundError if the file does not exist.
"""
with errors.raise_exception_on_not_ok_status() as status:
pywrap_tensorflow.DeleteFile(compat.as_bytes(filename), status)
示例6: walk
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def walk(top, in_order=True):
"""Recursive directory tree generator for directories.
Args:
top: string, a Directory name
in_order: bool, Traverse in order if True, post order if False.
Errors that happen while listing directories are ignored.
Yields:
Each yield is a 3-tuple: the pathname of a directory, followed by lists of
all its subdirectories and leaf files.
(dirname, [subdirname, subdirname, ...], [filename, filename, ...])
as strings
"""
top = compat.as_str_any(top)
try:
listing = list_directory(top)
except errors.NotFoundError:
return
files = []
subdirs = []
for item in listing:
full_path = os.path.join(top, item)
if is_directory(full_path):
subdirs.append(item)
else:
files.append(item)
here = (top, subdirs, files)
if in_order:
yield here
for subdir in subdirs:
for subitem in walk(os.path.join(top, subdir), in_order):
yield subitem
if not in_order:
yield here
示例7: read_file_to_string
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def read_file_to_string(filename):
"""Reads the entire contents of a file to a string.
Args:
filename: string, path to a file
Returns:
contents of the file as a string
Raises:
errors.OpError: Raises variety of errors that are subtypes e.g.
NotFoundError etc.
"""
f = FileIO(filename, mode="r")
return f.read()
示例8: testErrorRaisedIfCheckpointDoesntExist
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testErrorRaisedIfCheckpointDoesntExist(self):
checkpoint_path = os.path.join(self.get_temp_dir(),
'this_file_doesnt_exist')
log_dir = os.path.join(self.get_temp_dir(), 'error_raised')
with self.assertRaises(errors.NotFoundError):
evaluation.evaluate_once('', checkpoint_path, log_dir)
示例9: testDestroyNonexistentTemporaryVariable
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testDestroyNonexistentTemporaryVariable(self):
with self.test_session(use_gpu=True):
var = gen_state_ops._temporary_variable([1, 2], tf.float32)
final = gen_state_ops._destroy_temporary_variable(var, var_name="bad")
with self.assertRaises(errors.NotFoundError):
final.eval()
示例10: testDestroyTemporaryVariableTwice
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testDestroyTemporaryVariableTwice(self):
with self.test_session(use_gpu=True):
var = gen_state_ops._temporary_variable([1, 2], tf.float32)
val1 = gen_state_ops._destroy_temporary_variable(var, var_name="dup")
val2 = gen_state_ops._destroy_temporary_variable(var, var_name="dup")
final = val1 + val2
with self.assertRaises(errors.NotFoundError):
final.eval()
示例11: testWriteEvents
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testWriteEvents(self):
file_prefix = os.path.join(self.get_temp_dir(), "events")
writer = pywrap_tensorflow.EventsWriter(compat.as_bytes(file_prefix))
filename = compat.as_text(writer.FileName())
event_written = event_pb2.Event(
wall_time=123.45, step=67,
summary=summary_pb2.Summary(
value=[summary_pb2.Summary.Value(tag="foo", simple_value=89.0)]))
writer.WriteEvent(event_written)
writer.Flush()
writer.Close()
with self.assertRaises(errors.NotFoundError):
for r in tf_record.tf_record_iterator(filename + "DOES_NOT_EXIST"):
self.assertTrue(False)
reader = tf_record.tf_record_iterator(filename)
event_read = event_pb2.Event()
event_read.ParseFromString(next(reader))
self.assertTrue(event_read.HasField("file_version"))
event_read.ParseFromString(next(reader))
# Second event
self.assertProtoEquals("""
wall_time: 123.45 step: 67
summary { value { tag: 'foo' simple_value: 89.0 } }
""", event_read)
with self.assertRaises(StopIteration):
next(reader)
示例12: testInvalidTargetFails
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testInvalidTargetFails(self):
with self.assertRaisesRegexp(
errors.NotFoundError,
'No session factory registered for the given session options'):
session.Session('INVALID_TARGET')
示例13: testDebugString
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testDebugString(self):
# Builds a graph.
v0 = tf.Variable([[1, 2, 3], [4, 5, 6]], dtype=tf.float32, name="v0")
v1 = tf.Variable([[[1], [2]], [[3], [4]], [[5], [6]]], dtype=tf.float32,
name="v1")
init_all_op = tf.global_variables_initializer()
save = tf.train.Saver(
{"v0": v0,
"v1": v1}, write_version=self._WRITE_VERSION)
save_path = os.path.join(self.get_temp_dir(),
"ckpt_for_debug_string" + str(self._WRITE_VERSION))
with self.test_session() as sess:
sess.run(init_all_op)
# Saves a checkpoint.
save.save(sess, save_path)
# Creates a reader.
reader = tf.train.NewCheckpointReader(save_path)
# Verifies that the tensors exist.
self.assertTrue(reader.has_tensor("v0"))
self.assertTrue(reader.has_tensor("v1"))
debug_string = reader.debug_string()
# Verifies that debug string contains the right strings.
self.assertTrue(compat.as_bytes("v0 (DT_FLOAT) [2,3]") in debug_string)
self.assertTrue(compat.as_bytes("v1 (DT_FLOAT) [3,2,1]") in debug_string)
# Verifies get_variable_to_shape_map() returns the correct information.
var_map = reader.get_variable_to_shape_map()
self.assertEquals([2, 3], var_map["v0"])
self.assertEquals([3, 2, 1], var_map["v1"])
# Verifies get_tensor() returns the tensor value.
v0_tensor = reader.get_tensor("v0")
v1_tensor = reader.get_tensor("v1")
self.assertAllEqual(v0.eval(), v0_tensor)
self.assertAllEqual(v1.eval(), v1_tensor)
# Verifies get_tensor() fails for non-existent tensors.
with self.assertRaisesRegexp(errors.NotFoundError,
"v3 not found in checkpoint"):
reader.get_tensor("v3")
示例14: testNonexistentPath
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testNonexistentPath(self):
with self.assertRaisesRegexp(errors.NotFoundError,
"Unsuccessful TensorSliceReader"):
tf.train.NewCheckpointReader("non-existent")
示例15: testErrorRaisedIfCheckpointDoesntExist
# 需要導入模塊: from tensorflow.python.framework import errors [as 別名]
# 或者: from tensorflow.python.framework.errors import NotFoundError [as 別名]
def testErrorRaisedIfCheckpointDoesntExist(self):
checkpoint_path = os.path.join(self.get_temp_dir(),
'this_file_doesnt_exist')
log_dir = os.path.join(self.get_temp_dir(), 'error_raised')
with self.assertRaises(errors.NotFoundError):
slim.evaluation.evaluate_once('', checkpoint_path, log_dir)