Python tensorflow.python.framework.errors.NotFoundError() Examples
The following are 30
code examples of tensorflow.python.framework.errors.NotFoundError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.framework.errors
, or try the search function
.
Example #1
Source File: file_io.py From keras-lambda with MIT License | 6 votes |
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
Example #2
Source File: ffmpeg_ops.py From deep_image_model with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: secure_random.py From tf-encrypted with Apache License 2.0 | 6 votes |
def _try_load_secure_random_module(): """ Attempt to load and return secure random module; returns None if failed. """ so_file = SO_PATH.format(dn=os.path.dirname(tfe.__file__), tfv=tf.__version__) if not os.path.exists(so_file): logger.warning( ( "Falling back to insecure randomness since the required custom op " "could not be found for the installed version of TensorFlow. Fix " "this by compiling custom ops. Missing file was '%s'" ), so_file, ) return None try: return tf.load_op_library(so_file) except NotFoundError as ex: logger.warning( ( "Falling back to insecure randomness since the required custom op " "could not be found for the installed version of TensorFlow. Fix " "this by compiling custom ops. " "Missing file was '%s', error was \"%s\"." ), so_file, ex, ) except Exception as ex: # pylint: disable=broad-except logger.error( ( "Falling back to insecure randomness since an error occurred " 'loading the required custom op: "%s".' ), ex, ) return None
Example #4
Source File: file_io.py From lambda-packs with MIT License | 6 votes |
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
Example #5
Source File: file_io.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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
Example #6
Source File: file_io.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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()
Example #7
Source File: file_io.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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) ]
Example #8
Source File: ffmpeg_ops.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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)
Example #9
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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) ]
Example #10
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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
Example #11
Source File: file_io.py From keras-lambda with MIT License | 6 votes |
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) ]
Example #12
Source File: file_io.py From lambda-packs with MIT License | 6 votes |
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) ]
Example #13
Source File: file_io.py From lambda-packs with MIT License | 6 votes |
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()
Example #14
Source File: ffmpeg_ops.py From keras-lambda with MIT License | 6 votes |
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)
Example #15
Source File: file_io.py From keras-lambda with MIT License | 5 votes |
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)
Example #16
Source File: saver_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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")
Example #17
Source File: file_io.py From keras-lambda with MIT License | 5 votes |
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()
Example #18
Source File: file_io.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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
Example #19
Source File: file_io.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #20
Source File: evaluation_test.py From keras-lambda with MIT License | 5 votes |
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)
Example #21
Source File: evaluation_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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)
Example #22
Source File: saver_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testNonexistentPath(self): with self.assertRaisesRegexp(errors.NotFoundError, "Unsuccessful TensorSliceReader"): tf.train.NewCheckpointReader("non-existent")
Example #23
Source File: session_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testInvalidTargetFails(self): with self.assertRaisesRegexp( errors.NotFoundError, 'No session factory registered for the given session options'): session.Session('INVALID_TARGET')
Example #24
Source File: events_writer_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: variable_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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()
Example #26
Source File: variable_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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()
Example #27
Source File: evaluation_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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)
Example #28
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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()
Example #29
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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)
Example #30
Source File: file_io.py From lambda-packs with MIT License | 5 votes |
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