Python tensorflow.python.framework.errors.OpError() Examples
The following are 30
code examples of tensorflow.python.framework.errors.OpError().
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 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 #2
Source File: directory_watcher.py From lambda-packs with MIT License | 6 votes |
def Load(self): """Loads new values. The watcher will load from one path at a time; as soon as that path stops yielding events, it will move on to the next path. We assume that old paths are never modified after a newer path has been written. As a result, Load() can be called multiple times in a row without losing events that have not been yielded yet. In other words, we guarantee that every event will be yielded exactly once. Yields: All values that have not been yielded yet. Raises: DirectoryDeletedError: If the directory has been permanently deleted (as opposed to being temporarily unavailable). """ try: for event in self._LoadInternal(): yield event except errors.OpError: if not gfile.Exists(self._directory): raise DirectoryDeletedError( 'Directory %s has been permanently deleted' % self._directory)
Example #3
Source File: directory_watcher.py From lambda-packs with MIT License | 6 votes |
def _SetPath(self, path): """Sets the current path to watch for new events. This also records the size of the old path, if any. If the size can't be found, an error is logged. Args: path: The full path of the file to watch. """ old_path = self._path if old_path and not io_wrapper.IsGCSPath(old_path): try: # We're done with the path, so store its size. size = gfile.Stat(old_path).length logging.debug('Setting latest size of %s to %d', old_path, size) self._finalized_sizes[old_path] = size except errors.OpError as e: logging.error('Unable to get size of %s: %s', old_path, e) self._path = path self._loader = self._loader_factory(path)
Example #4
Source File: file_io.py From lambda-packs with MIT License | 6 votes |
def stat(filename): """Returns file statistics for a given path. Args: filename: string, path to a file Returns: FileStatistics struct that contains information about the path Raises: errors.OpError: If the operation fails. """ file_statistics = pywrap_tensorflow.FileStatistics() with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.Stat(compat.as_bytes(filename), file_statistics, status) return file_statistics
Example #5
Source File: directory_watcher.py From deep_image_model with Apache License 2.0 | 6 votes |
def Load(self): """Loads new values. The watcher will load from one path at a time; as soon as that path stops yielding events, it will move on to the next path. We assume that old paths are never modified after a newer path has been written. As a result, Load() can be called multiple times in a row without losing events that have not been yielded yet. In other words, we guarantee that every event will be yielded exactly once. Yields: All values that have not been yielded yet. Raises: DirectoryDeletedError: If the directory has been permanently deleted (as opposed to being temporarily unavailable). """ try: for event in self._LoadInternal(): yield event except errors.OpError: if not gfile.Exists(self._directory): raise DirectoryDeletedError( 'Directory %s has been permanently deleted' % self._directory)
Example #6
Source File: directory_watcher.py From deep_image_model with Apache License 2.0 | 6 votes |
def _SetPath(self, path): """Sets the current path to watch for new events. This also records the size of the old path, if any. If the size can't be found, an error is logged. Args: path: The full path of the file to watch. """ old_path = self._path if old_path and not io_wrapper.IsGCSPath(old_path): try: # We're done with the path, so store its size. size = gfile.Stat(old_path).length logging.debug('Setting latest size of %s to %d', old_path, size) self._finalized_sizes[old_path] = size except errors.OpError as e: logging.error('Unable to get size of %s: %s', old_path, e) self._path = path self._loader = self._loader_factory(path)
Example #7
Source File: session.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _do_call(self, fn, *args): try: return fn(*args) except errors.OpError as e: message = compat.as_text(e.message) m = BaseSession._NODEDEF_NAME_RE.search(message) node_def = None op = None if m is not None: node_name = m.group(1) try: op = self._graph.get_operation_by_name(node_name) node_def = op.node_def except KeyError: pass raise type(e)(node_def, op, message)
Example #8
Source File: session.py From deep_image_model with Apache License 2.0 | 6 votes |
def _do_call(self, fn, *args): try: return fn(*args) except errors.OpError as e: message = compat.as_text(e.message) m = BaseSession._NODEDEF_NAME_RE.search(message) node_def = None op = None if m is not None: node_name = m.group(1) try: op = self._graph.get_operation_by_name(node_name) node_def = op.node_def except KeyError: pass raise type(e)(node_def, op, message)
Example #9
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 #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: directory_watcher.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _SetPath(self, path): """Sets the current path to watch for new events. This also records the size of the old path, if any. If the size can't be found, an error is logged. Args: path: The full path of the file to watch. """ old_path = self._path if old_path and not io_wrapper.IsGCSPath(old_path): try: # We're done with the path, so store its size. size = gfile.Stat(old_path).length logging.debug('Setting latest size of %s to %d', old_path, size) self._finalized_sizes[old_path] = size except errors.OpError as e: logging.error('Unable to get size of %s: %s', old_path, e) self._path = path self._loader = self._loader_factory(path)
Example #12
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def stat(filename): """Returns file statistics for a given path. Args: filename: string, path to a file Returns: FileStatistics struct that contains information about the path Raises: errors.OpError: If the operation fails. """ file_statistics = pywrap_tensorflow.FileStatistics() with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.Stat(compat.as_bytes(filename), file_statistics, status) return file_statistics
Example #13
Source File: session.py From lambda-packs with MIT License | 6 votes |
def _do_call(self, fn, *args): try: return fn(*args) except errors.OpError as e: message = compat.as_text(e.message) m = BaseSession._NODEDEF_NAME_RE.search(message) node_def = None op = None if m is not None: node_name = m.group(1) try: op = self._graph.get_operation_by_name(node_name) node_def = op.node_def except KeyError: pass raise type(e)(node_def, op, message)
Example #14
Source File: linear_model_test.py From estimator with Apache License 2.0 | 6 votes |
def test_linear_model_mismatched_dense_values(self): column = fc.weighted_categorical_column( categorical_column=fc.categorical_column_with_identity( key='ids', num_buckets=3), weight_feature_key='values') with ops.Graph().as_default(): model = linear.LinearModel((column,), sparse_combiner='mean') predictions = model({ 'ids': sparse_tensor.SparseTensorValue( indices=((0, 0), (1, 0), (1, 1)), values=(0, 2, 1), dense_shape=(2, 2)), 'values': ((.5,), (1.,)) }) # Disabling the constant folding optimizer here since it changes the # error message differently on CPU and GPU. config = config_pb2.ConfigProto() config.graph_options.rewrite_options.constant_folding = ( rewriter_config_pb2.RewriterConfig.OFF) with _initialized_session(config): with self.assertRaisesRegexp(errors.OpError, 'Incompatible shapes'): self.evaluate(predictions)
Example #15
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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)]
Example #16
Source File: googletest.py From lambda-packs with MIT License | 6 votes |
def GetTempDir(): """Return a temporary directory for tests to use.""" global _googletest_temp_dir if not _googletest_temp_dir: first_frame = tf_inspect.stack()[-1][0] temp_dir = os.path.join(tempfile.gettempdir(), os.path.basename(tf_inspect.getfile(first_frame))) temp_dir = tempfile.mkdtemp(prefix=temp_dir.rstrip('.py')) def delete_temp_dir(dirname=temp_dir): try: file_io.delete_recursively(dirname) except errors.OpError as e: logging.error('Error removing %s: %s', dirname, e) atexit.register(delete_temp_dir) _googletest_temp_dir = temp_dir return _googletest_temp_dir
Example #17
Source File: googletest.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def GetTempDir(): """Return a temporary directory for tests to use.""" global _googletest_temp_dir if not _googletest_temp_dir: first_frame = tf_inspect.stack()[-1][0] temp_dir = os.path.join(tempfile.gettempdir(), os.path.basename(tf_inspect.getfile(first_frame))) temp_dir = tempfile.mkdtemp(prefix=temp_dir.rstrip('.py')) def delete_temp_dir(dirname=temp_dir): try: file_io.delete_recursively(dirname) except errors.OpError as e: logging.error('Error removing %s: %s', dirname, e) atexit.register(delete_temp_dir) _googletest_temp_dir = temp_dir return _googletest_temp_dir
Example #18
Source File: trainer_lib.py From yolo_v2 with Apache License 2.0 | 5 votes |
def get_summary_writer(tensorboard_dir): """Creates a directory for writing summaries and returns a writer.""" tf.logging.info('TensorBoard directory: %s', tensorboard_dir) tf.logging.info('Deleting prior data if exists...') try: gfile.DeleteRecursively(tensorboard_dir) except errors.OpError as err: tf.logging.error('Directory did not exist? Error: %s', err) tf.logging.info('Deleted! Creating the directory again...') gfile.MakeDirs(tensorboard_dir) tf.logging.info('Created! Instatiating SummaryWriter...') summary_writer = tf.summary.FileWriter(tensorboard_dir) return summary_writer
Example #19
Source File: trainer_lib.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def get_summary_writer(tensorboard_dir): """Creates a directory for writing summaries and returns a writer.""" tf.logging.info('TensorBoard directory: %s', tensorboard_dir) tf.logging.info('Deleting prior data if exists...') try: gfile.DeleteRecursively(tensorboard_dir) except errors.OpError as err: tf.logging.error('Directory did not exist? Error: %s', err) tf.logging.info('Deleted! Creating the directory again...') gfile.MakeDirs(tensorboard_dir) tf.logging.info('Created! Instatiating SummaryWriter...') summary_writer = tf.summary.FileWriter(tensorboard_dir) return summary_writer
Example #20
Source File: trainer_lib.py From HumanRecognition with MIT License | 5 votes |
def get_summary_writer(tensorboard_dir): """Creates a directory for writing summaries and returns a writer.""" tf.logging.info('TensorBoard directory: %s', tensorboard_dir) tf.logging.info('Deleting prior data if exists...') try: gfile.DeleteRecursively(tensorboard_dir) except errors.OpError as err: tf.logging.error('Directory did not exist? Error: %s', err) tf.logging.info('Deleted! Creating the directory again...') gfile.MakeDirs(tensorboard_dir) tf.logging.info('Created! Instatiating SummaryWriter...') summary_writer = tf.summary.FileWriter(tensorboard_dir) return summary_writer
Example #21
Source File: linear_model_test.py From estimator with Apache License 2.0 | 5 votes |
def test_runtime_batch_size_mismatch(self): price1 = fc.numeric_column('price1') price2 = fc.numeric_column('price2') with ops.Graph().as_default(): features = { 'price1': array_ops.placeholder(dtype=dtypes.int64), # batchsize = 3 'price2': [[3.], [4.]] # batchsize = 2 } model = linear.LinearModel([price1, price2]) predictions = model(features) with _initialized_session() as sess: with self.assertRaisesRegexp(errors.OpError, 'must have the same size and shape'): sess.run( predictions, feed_dict={features['price1']: [[1.], [5.], [7.]]})
Example #22
Source File: framework.py From deep_image_model with Apache License 2.0 | 5 votes |
def __init__(self, performed_action, run_metadata=None, client_graph_def=None, tf_error=None): """Constructor for OnRunEndRequest. Args: performed_action: (OnRunStartAction) Actually-performed action by the debug-wrapper session. run_metadata: run_metadata output from the run() call (if any). client_graph_def: (GraphDef) GraphDef from the client side, i.e., from the python front end of TensorFlow. Can be obtained with session.graph.as_graph_def(). tf_error: (errors.OpError subtypes) TensorFlow OpError that occurred during the run (if any). """ _check_type(performed_action, str) self.performed_action = performed_action if run_metadata is not None: _check_type(run_metadata, config_pb2.RunMetadata) self.run_metadata = run_metadata self.client_graph_def = client_graph_def self.tf_error = tf_error
Example #23
Source File: trainer_lib.py From object_detection_with_tensorflow with MIT License | 5 votes |
def get_summary_writer(tensorboard_dir): """Creates a directory for writing summaries and returns a writer.""" tf.logging.info('TensorBoard directory: %s', tensorboard_dir) tf.logging.info('Deleting prior data if exists...') try: gfile.DeleteRecursively(tensorboard_dir) except errors.OpError as err: tf.logging.error('Directory did not exist? Error: %s', err) tf.logging.info('Deleted! Creating the directory again...') gfile.MakeDirs(tensorboard_dir) tf.logging.info('Created! Instatiating SummaryWriter...') summary_writer = tf.summary.FileWriter(tensorboard_dir) return summary_writer
Example #24
Source File: session_debug_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testRunWithError(self): """Test the debug tensor dumping when error occurs in graph runtime.""" with session.Session() as sess: ph = tf.placeholder(tf.float32, name="mismatch/ph") x = tf.transpose(ph, name="mismatch/x") m = constant_op.constant( np.array( [[1.0, 2.0]], dtype=np.float32), name="mismatch/m") y = math_ops.matmul(m, x, name="mismatch/y") run_options = config_pb2.RunOptions(output_partition_graphs=True) debug_utils.watch_graph( run_options, sess.graph, debug_ops=["DebugIdentity"], debug_urls="file://%s" % self._dump_root) with self.assertRaises(errors.OpError): sess.run(y, options=run_options, feed_dict={ph: np.array([[-3.0], [0.0]])}) dump = debug_data.DebugDumpDir(self._dump_root) self.assertFalse(dump.loaded_partition_graphs()) m_dumps = dump.watch_key_to_data("mismatch/m:0:DebugIdentity") self.assertEqual(1, len(m_dumps)) self.assertAllClose(np.array([[1.0, 2.0]]), m_dumps[0].get_tensor()) x_dumps = dump.watch_key_to_data("mismatch/x:0:DebugIdentity") self.assertEqual(1, len(x_dumps)) self.assertAllClose(np.array([[-3.0, 0.0]]), x_dumps[0].get_tensor())
Example #25
Source File: trainer_lib.py From Gun-Detector with Apache License 2.0 | 5 votes |
def get_summary_writer(tensorboard_dir): """Creates a directory for writing summaries and returns a writer.""" tf.logging.info('TensorBoard directory: %s', tensorboard_dir) tf.logging.info('Deleting prior data if exists...') try: gfile.DeleteRecursively(tensorboard_dir) except errors.OpError as err: tf.logging.error('Directory did not exist? Error: %s', err) tf.logging.info('Deleted! Creating the directory again...') gfile.MakeDirs(tensorboard_dir) tf.logging.info('Created! Instatiating SummaryWriter...') summary_writer = tf.summary.FileWriter(tensorboard_dir) return summary_writer
Example #26
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def rename(oldname, newname, overwrite=False): """Rename or move a file / directory. Args: oldname: string, pathname for a file newname: string, pathname to which the file needs to be moved overwrite: boolean, if false its an error for newpath to be occupied by an existing file. Raises: errors.OpError: If the operation fails. """ with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.RenameFile( compat.as_bytes(oldname), compat.as_bytes(newname), overwrite, status)
Example #27
Source File: test_util.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def assertRaisesOpError(self, expected_err_re_or_predicate): return self.assertRaisesWithPredicateMatch(errors.OpError, expected_err_re_or_predicate)
Example #28
Source File: test_util.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def assertRaisesWithPredicateMatch(self, exception_type, expected_err_re_or_predicate): """Returns a context manager to enclose code expected to raise an exception. If the exception is an OpError, the op stack is also included in the message predicate search. Args: exception_type: The expected type of exception that should be raised. expected_err_re_or_predicate: If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially. Returns: A context manager to surround code that is expected to raise an exception. """ if callable(expected_err_re_or_predicate): predicate = expected_err_re_or_predicate else: def predicate(e): err_str = e.message if isinstance(e, errors.OpError) else str(e) op = e.op if isinstance(e, errors.OpError) else None while op is not None: err_str += "\nCaused by: " + op.name op = op._original_op logging.info("Searching within error strings: '%s' within '%s'", expected_err_re_or_predicate, err_str) return re.search(expected_err_re_or_predicate, err_str) try: yield self.fail(exception_type.__name__ + " not raised") except Exception as e: # pylint: disable=broad-except if not isinstance(e, exception_type) or not predicate(e): raise AssertionError("Exception of type %s: %s" % (str(type(e)), str(e))) # pylint: enable=g-doc-return-or-yield
Example #29
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def delete_recursively(dirname): """Deletes everything under dirname recursively. Args: dirname: string, a path to a directory Raises: errors.OpError: If the operation fails. """ with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.DeleteRecursively(compat.as_bytes(dirname), status)
Example #30
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def copy(oldpath, newpath, overwrite=False): """Copies data from oldpath to newpath. Args: oldpath: string, name of the file who's contents need to be copied newpath: string, name of the file to which to copy to overwrite: boolean, if false its an error for newpath to be occupied by an existing file. Raises: errors.OpError: If the operation fails. """ with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.CopyFile( compat.as_bytes(oldpath), compat.as_bytes(newpath), overwrite, status)