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


Python gfile.Copy方法代码示例

本文整理汇总了Python中tensorflow.python.platform.gfile.Copy方法的典型用法代码示例。如果您正苦于以下问题:Python gfile.Copy方法的具体用法?Python gfile.Copy怎么用?Python gfile.Copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.platform.gfile的用法示例。


在下文中一共展示了gfile.Copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: maybe_download

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def maybe_download(filename, work_directory, source_url):
  """Download the data from source url, unless it's already here.

  Args:
      filename: string, name of the file in the directory.
      work_directory: string, path to working directory.
      source_url: url to download from if file doesn't exist.

  Returns:
      Path to resulting file.
  """
  if not gfile.Exists(work_directory):
    gfile.MakeDirs(work_directory)
  filepath = os.path.join(work_directory, filename)
  if not gfile.Exists(filepath):
    temp_file_name, _ = urlretrieve_with_retry(source_url)
    gfile.Copy(temp_file_name, filepath)
    with gfile.GFile(filepath) as f:
      size = f.size()
    print('Successfully downloaded', filename, size, 'bytes.')
  return filepath 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:23,代码来源:base.py

示例2: _recursive_copy

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def _recursive_copy(src_dir, dest_dir):
  """Copy the contents of src_dir into the folder dest_dir.
  Args:
    src_dir: gsc or local path.
    dest_dir: gcs or local path.
  When called, dest_dir should exist.
  """
  src_dir = python_portable_string(src_dir)
  dest_dir = python_portable_string(dest_dir)

  file_io.recursive_create_dir(dest_dir)
  for file_name in file_io.list_directory(src_dir):
    old_path = os.path.join(src_dir, file_name)
    new_path = os.path.join(dest_dir, file_name)

    if file_io.is_directory(old_path):
      _recursive_copy(old_path, new_path)
    else:
      file_io.copy(old_path, new_path, overwrite=True) 
开发者ID:googledatalab,项目名称:pydatalab,代码行数:21,代码来源:util.py

示例3: maybe_download

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def maybe_download(filename, work_directory, source_url):
  """Download the data from source url, unless it's already here.

  Args:
      filename: string, name of the file in the directory.
      work_directory: string, path to working directory.
      source_url: url to download from if file doesn't exist.

  Returns:
      Path to resulting file.
  """
  if not gfile.Exists(work_directory):
    gfile.MakeDirs(work_directory)
  filepath = os.path.join(work_directory, filename)
  if not gfile.Exists(filepath):
    with tempfile.NamedTemporaryFile() as tmpfile:
      temp_file_name = tmpfile.name
      urllib.request.urlretrieve(source_url, temp_file_name)
      gfile.Copy(temp_file_name, filepath)
      with gfile.GFile(filepath) as f:
        size = f.size()
      print('Successfully downloaded', filename, size, 'bytes.')
  return filepath 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:25,代码来源:base.py

示例4: maybe_download_and_extract

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def maybe_download_and_extract(filename, data_dir, source_url):
  """Maybe download and extract a file."""
  if not gfile.Exists(data_dir):
    gfile.MakeDirs(data_dir)

  filepath = os.path.join(data_dir, filename)

  if not gfile.Exists(filepath):
    print('Downloading from {}'.format(source_url))
    temp_file_name, _ = urllib.request.urlretrieve(source_url)
    gfile.Copy(temp_file_name, filepath)
    with gfile.GFile(filepath) as f:
      size = f.size()
    print('Successfully downloaded \'{}\' of {} bytes'.format(filename, size))

  if filename.endswith('.zip'):
    print('Extracting {}'.format(filename))
    zipfile.ZipFile(file=filepath, mode='r').extractall(data_dir) 
开发者ID:GoogleCloudPlatform,项目名称:solutions-vision-search,代码行数:20,代码来源:task.py

示例5: maybe_download

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def maybe_download(filepath, source_url):
  """Download the data from source url, unless it's already here.
  Args:
      basename: string, name of the file in the directory.
      target_dir: string, path to working directory.
      source_url: url to download from if file doesn't exist.
  Returns:
      Path to resulting file.
  """
  target_dir = path.dirname(filepath)
  if not gfile.Exists(target_dir):
    gfile.MakeDirs(target_dir)
  if not gfile.Exists(filepath):
    print('Downloading', source_url, 'to', filepath)
    temp_file_name, _ = _urlretrieve_with_retry(source_url)
    gfile.Copy(temp_file_name, filepath)
    with gfile.GFile(filepath) as f:
      size = f.size()
    print('Successfully downloaded', filepath, size, 'bytes.')
  return filepath 
开发者ID:tensorlang,项目名称:tensorlang,代码行数:22,代码来源:graph_assets.py

示例6: gfile_copy_callback

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def gfile_copy_callback(files_to_copy, export_dir_path):
  """Callback to copy files using `gfile.Copy` to an export directory.

  This method is used as the default `assets_callback` in `Exporter.init` to
  copy assets from the `assets_collection`. It can also be invoked directly to
  copy additional supplementary files into the export directory (in which case
  it is not a callback).

  Args:
    files_to_copy: A dictionary that maps original file paths to desired
      basename in the export directory.
    export_dir_path: Directory to copy the files to.
  """
  logging.info("Write assets into: %s using gfile_copy.", export_dir_path)
  gfile.MakeDirs(export_dir_path)
  for source_filepath, basename in files_to_copy.items():
    new_path = os.path.join(
        compat.as_bytes(export_dir_path), compat.as_bytes(basename))
    logging.info("Copying asset %s to path %s.", source_filepath, new_path)

    if gfile.Exists(new_path):
      # Guard against being restarted while copying assets, and the file
      # existing and being in an unknown state.
      # TODO(b/28676216): Do some file checks before deleting.
      logging.info("Removing file %s.", new_path)
      gfile.Remove(new_path)
    gfile.Copy(source_filepath, new_path) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:29,代码来源:exporter.py

示例7: edit_pb_txt

# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Copy [as 别名]
def edit_pb_txt(old_args, export_dir):
  """
  Edit file path argument in pbtxt file.
  :param old_args: Old file paths need to be copied and edited.
  :param export_dir: Directory of the saved model.
  """
  assets_extra_dir = os.path.join(export_dir, "./assets.extra")
  if not os.path.exists(assets_extra_dir):
    os.makedirs(assets_extra_dir)

  new_args = []
  for one_old in old_args:
    if not os.path.exists(one_old):
      raise ValueError("{} do not exists!".format(one_old))
    one_new = os.path.join(assets_extra_dir, os.path.basename(one_old))
    new_args.append(one_new)
    logging.info("Copy file: {} to: {}".format(one_old, one_new))
    gfile.Copy(one_old, one_new, overwrite=True)

  pbtxt_file = os.path.join(export_dir, "saved_model.pbtxt")
  tmp_file = pbtxt_file + ".tmp"
  logging.info("Editing pbtxt file: {}".format(pbtxt_file))
  with open(pbtxt_file, "rt") as fin, open(tmp_file, "wt") as fout:
    for line in fin:
      for one_old, one_new in zip(old_args, new_args):
        line = line.replace(one_old, one_new)
      fout.write(line)
  gfile.Copy(tmp_file, pbtxt_file, overwrite=True)
  gfile.Remove(tmp_file) 
开发者ID:didi,项目名称:delta,代码行数:31,代码来源:replace_custom_op_attr_pbtxt.py


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