Python tensorflow.python.framework.errors.raise_exception_on_not_ok_status() Examples
The following are 30
code examples of tensorflow.python.framework.errors.raise_exception_on_not_ok_status().
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: session.py From deep_image_model with Apache License 2.0 | 6 votes |
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.
Example #2
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 #3
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 #4
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 #5
Source File: file_io.py From lambda-packs with MIT License | 6 votes |
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))
Example #6
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 #7
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 #8
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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)
Example #9
Source File: session.py From lambda-packs with MIT License | 6 votes |
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.
Example #10
Source File: session.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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)
Example #11
Source File: session.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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.
Example #12
Source File: session.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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.
Example #13
Source File: context.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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)
Example #14
Source File: context.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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)
Example #15
Source File: event_file_loader.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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)
Example #16
Source File: pywrap_tensorflow_internal.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #17
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 #18
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 #19
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 #20
Source File: pywrap_tensorflow_internal.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def list_devices(): from tensorflow.python.framework import errors with errors.raise_exception_on_not_ok_status() as status: return ListDevices(status)
Example #21
Source File: session.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def list_devices(self): """Lists available devices in this session. ```python devices = sess.list_devices() for d in devices: print(d.name) ``` Each element in the list has the following properties: - `name`: A string with the full name of the device. ex: `/job:worker/replica:0/task:3/device:CPU:0` - `device_type`: The type of the device (e.g. `CPU`, `GPU`, `TPU`.) - `memory_limit`: The maximum amount of memory available on the device. Note: depending on the device, it is possible the usable memory could be substantially less. Raises: tf.errors.OpError: If it encounters an error (e.g. session is in an invalid state, or network errors occur). Returns: A list of devices in the session. """ with errors.raise_exception_on_not_ok_status() as status: if self._created_with_new_api: raw_device_list = tf_session.TF_SessionListDevices( self._session, status) else: raw_device_list = tf_session.TF_DeprecatedSessionListDevices( self._session, status) device_list = [] size = tf_session.TF_DeviceListCount(raw_device_list) for i in range(size): name = tf_session.TF_DeviceListName(raw_device_list, i, status) device_type = tf_session.TF_DeviceListType(raw_device_list, i, status) memory = tf_session.TF_DeviceListMemoryBytes(raw_device_list, i, status) device_list.append(_DeviceAttributes(name, device_type, memory)) tf_session.TF_DeleteDeviceList(raw_device_list) return device_list
Example #22
Source File: pywrap_tensorflow_internal.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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
Example #23
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)
Example #24
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def recursive_create_dir(dirname): """Creates a directory and all parent/intermediate directories. It succeeds if dirname already exists and is writable. Args: dirname: string, name of the directory to be created Raises: errors.OpError: If the operation fails. """ with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(dirname), status)
Example #25
Source File: session.py From deep_image_model with Apache License 2.0 | 5 votes |
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. """ 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)
Example #26
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def close(self): """Closes FileIO. Should be called for the WritableFile to be flushed.""" self._read_buf = None if self._writable_file: with errors.raise_exception_on_not_ok_status() as status: ret_status = self._writable_file.Close() pywrap_tensorflow.Set_TF_Status_from_Status(status, ret_status) self._writable_file = None
Example #27
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def flush(self): """Flushes the Writable file. This only ensures that the data has made its way out of the process without any guarantees on whether it's written to disk. This means that the data would survive an application crash but not necessarily an OS crash. """ if self._writable_file: with errors.raise_exception_on_not_ok_status() as status: ret_status = self._writable_file.Flush() pywrap_tensorflow.Set_TF_Status_from_Status(status, ret_status)
Example #28
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def write(self, file_content): """Writes file_content to the file. Appends to the end of the file.""" self._prewrite_check() with errors.raise_exception_on_not_ok_status() as status: pywrap_tensorflow.AppendToFile( compat.as_bytes(file_content), self._writable_file, status)
Example #29
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _prewrite_check(self): if not self._writable_file: if not self._write_check_passed: raise errors.PermissionDeniedError(None, None, "File isn't open for writing") with errors.raise_exception_on_not_ok_status() as status: self._writable_file = pywrap_tensorflow.CreateWritableFile( compat.as_bytes(self.__name), compat.as_bytes(self.__mode), status)
Example #30
Source File: file_io.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _preread_check(self): if not self._read_buf: if not self._read_check_passed: raise errors.PermissionDeniedError(None, None, "File isn't open for reading") with errors.raise_exception_on_not_ok_status() as status: self._read_buf = pywrap_tensorflow.CreateBufferedInputStream( compat.as_bytes(self.__name), 1024 * 512, status)