本文整理匯總了Python中tensorflow.python.util.compat.as_bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.as_bytes方法的具體用法?Python compat.as_bytes怎麽用?Python compat.as_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.util.compat
的用法示例。
在下文中一共展示了compat.as_bytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_timestamped_export_dir
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def get_timestamped_export_dir(export_dir_base):
"""Builds a path to a new subdirectory within the base directory.
Each export is written into a new subdirectory named using the
current time. This guarantees monotonically increasing version
numbers even across multiple runs of the pipeline.
The timestamp used is the number of seconds since epoch UTC.
Args:
export_dir_base: A string containing a directory to write the exported
graph and checkpoints.
Returns:
The full path of the new subdirectory (which is not actually created yet).
"""
export_timestamp = int(time.time())
export_dir = os.path.join(
compat.as_bytes(export_dir_base),
compat.as_bytes(str(export_timestamp)))
return export_dir
示例2: file_exists
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [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
示例3: list_directory
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [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: stat
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
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
示例5: get_timestamped_export_dir
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def get_timestamped_export_dir(export_dir_base):
"""Builds a path to a new subdirectory within the base directory.
Each export is written into a new subdirectory named using the
current time. This guarantees monotonically increasing version
numbers even across multiple runs of the pipeline.
The timestamp used is the number of seconds since epoch UTC.
Args:
export_dir_base: A string containing a directory to write the exported
graph and checkpoints.
Returns:
The full path of the new subdirectory (which is not actually created yet).
"""
export_timestamp = int(time.time())
export_dir = os.path.join(
compat.as_bytes(export_dir_base),
compat.as_bytes(str(export_timestamp)))
return export_dir
# create a simple parser that pulls the export_version from the directory.
示例6: _maybe_export
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def _maybe_export(self, eval_result, checkpoint_path=None):
"""Export the Estimator using export_fn, if defined."""
export_dir_base = os.path.join(
compat.as_bytes(self._estimator.model_dir),
compat.as_bytes("export"))
export_results = []
for strategy in self._export_strategies:
export_results.append(
strategy.export(
self._estimator,
os.path.join(
compat.as_bytes(export_dir_base),
compat.as_bytes(strategy.name)),
checkpoint_path=checkpoint_path,
eval_result=eval_result))
return export_results
示例7: get_matching_files
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [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)]
示例8: colocation_groups
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def colocation_groups(self):
"""Returns the list of colocation groups of the op."""
default_colocation_group = [compat.as_bytes("loc:@%s" %
self._node_def.name)]
if "_class" not in self._node_def.attr:
# This op has no explicit colocation group, so it is itself its
# own root of a colocation group.
return default_colocation_group
attr_groups = [class_name
for class_name in self.get_attr("_class")
if class_name.startswith(b"loc:@")]
# If there are no colocation groups in the explicit _class field,
# return the default colocation group.
return attr_groups if attr_groups else default_colocation_group
示例9: __init__
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def __init__(self, dir):
os.makedirs(dir, exist_ok=True)
self.dir = dir
self.step = 1
prefix = 'events'
path = osp.join(osp.abspath(dir), prefix)
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow
from tensorflow.core.util import event_pb2
from tensorflow.python.util import compat
self.tf = tf
self.event_pb2 = event_pb2
self.pywrap_tensorflow = pywrap_tensorflow
self.writer = pywrap_tensorflow.EventsWriter(compat.as_bytes(path))
示例10: __init__
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def __init__(self, dir, prefix):
self.dir = dir
self.step = 1 # Start at 1, because EvWriter automatically generates an object with step=0
self.evwriter = pywrap_tensorflow.EventsWriter(compat.as_bytes(os.path.join(dir, prefix)))
示例11: _save_and_write_assets
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def _save_and_write_assets(self, assets_collection_to_add=None):
"""Saves asset to the meta graph and writes asset files to disk.
Args:
assets_collection_to_add: The collection where the asset paths are setup.
"""
asset_source_filepath_list = _maybe_save_assets(assets_collection_to_add)
# Return if there are no assets to write.
if len(asset_source_filepath_list) is 0:
tf_logging.info("No assets to write.")
return
assets_destination_dir = os.path.join(
compat.as_bytes(self._export_dir),
compat.as_bytes(constants.ASSETS_DIRECTORY))
if not file_io.file_exists(assets_destination_dir):
file_io.recursive_create_dir(assets_destination_dir)
# Copy each asset from source path to destination path.
for asset_source_filepath in asset_source_filepath_list:
asset_source_filename = os.path.basename(asset_source_filepath)
asset_destination_filepath = os.path.join(
compat.as_bytes(assets_destination_dir),
compat.as_bytes(asset_source_filename))
# Only copy the asset file to the destination if it does not already
# exist. This is to ensure that an asset with the same name defined as
# part of multiple graphs is only copied the first time.
if not file_io.file_exists(asset_destination_filepath):
file_io.copy(asset_source_filepath, asset_destination_filepath)
tf_logging.info("Assets written to: %s", assets_destination_dir)
示例12: save
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def save(self, as_text=False):
"""Writes a `SavedModel` protocol buffer to disk.
The function writes the SavedModel protocol buffer to the export directory
in serialized format.
Args:
as_text: Writes the SavedModel protocol buffer in text format to disk.
Returns:
The path to which the SavedModel protocol buffer was written.
"""
if not file_io.file_exists(self._export_dir):
file_io.recursive_create_dir(self._export_dir)
if as_text:
path = os.path.join(
compat.as_bytes(self._export_dir),
compat.as_bytes(constants.SAVED_MODEL_FILENAME_PBTXT))
file_io.write_string_to_file(path, str(self._saved_model))
else:
path = os.path.join(
compat.as_bytes(self._export_dir),
compat.as_bytes(constants.SAVED_MODEL_FILENAME_PB))
file_io.write_string_to_file(path, self._saved_model.SerializeToString())
tf_logging.info("SavedModel written to: %s", path)
return path
示例13: _get_asset_tensors
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def _get_asset_tensors(export_dir, meta_graph_def_to_load):
"""Gets the asset tensors, if defined in the meta graph def to load.
Args:
export_dir: Directory where the SavedModel is located.
meta_graph_def_to_load: The meta graph def from the SavedModel to be loaded.
Returns:
A dictionary of asset tensors, keyed by the name of the asset tensor. The
value in the map corresponds to the absolute path of the asset file.
"""
# Collection-def that may contain the assets key.
collection_def = meta_graph_def_to_load.collection_def
asset_tensor_dict = {}
if constants.ASSETS_KEY in collection_def:
# Location of the assets for SavedModel.
assets_directory = os.path.join(
compat.as_bytes(export_dir),
compat.as_bytes(constants.ASSETS_DIRECTORY))
assets_any_proto = collection_def[constants.ASSETS_KEY].any_list.value
# Process each asset and add it to the asset tensor dictionary.
for asset_any_proto in assets_any_proto:
asset_proto = meta_graph_pb2.AssetFileDef()
asset_any_proto.Unpack(asset_proto)
asset_tensor_dict[asset_proto.tensor_info.name] = os.path.join(
compat.as_bytes(assets_directory),
compat.as_bytes(asset_proto.filename))
return asset_tensor_dict
示例14: has_tensor
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [as 別名]
def has_tensor(self, tensor_str):
from tensorflow.python.util import compat
return self._HasTensor(compat.as_bytes(tensor_str))
示例15: get_tensor
# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_bytes [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)