当前位置: 首页>>代码示例>>Python>>正文


Python compat.as_bytes方法代码示例

本文整理汇总了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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:export.py

示例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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:file_io.py

示例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)
    ] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:file_io.py

示例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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:file_io.py

示例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. 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:25,代码来源:saved_model_export_utils.py

示例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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:experiment.py

示例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)] 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:20,代码来源:file_io.py

示例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 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:ops.py

示例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)) 
开发者ID:Hwhitetooth,项目名称:lirpg,代码行数:16,代码来源:logger.py

示例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))) 
开发者ID:openai,项目名称:evolution-strategies-starter,代码行数:6,代码来源:tabular_logger.py

示例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) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:37,代码来源:builder_impl.py

示例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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:builder_impl.py

示例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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:31,代码来源:loader_impl.py

示例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)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:5,代码来源:pywrap_tensorflow_internal.py

示例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) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:pywrap_tensorflow_internal.py


注:本文中的tensorflow.python.util.compat.as_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。