當前位置: 首頁>>代碼示例>>Python>>正文


Python gfile.Walk方法代碼示例

本文整理匯總了Python中tensorflow.python.platform.gfile.Walk方法的典型用法代碼示例。如果您正苦於以下問題:Python gfile.Walk方法的具體用法?Python gfile.Walk怎麽用?Python gfile.Walk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.platform.gfile的用法示例。


在下文中一共展示了gfile.Walk方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ListRecursively

# 需要導入模塊: from tensorflow.python.platform import gfile [as 別名]
# 或者: from tensorflow.python.platform.gfile import Walk [as 別名]
def ListRecursively(top):
  """Walks a directory tree, yielding (dir_path, file_paths) tuples.

  For each of `top` and its subdirectories, yields a tuple containing the path
  to the directory and the path to each of the contained files.  Note that
  unlike os.Walk()/gfile.Walk(), this does not list subdirectories and the file
  paths are all absolute.

  If the directory does not exist, this yields nothing.

  Args:
    top: A path to a directory..
  Yields:
    A list of (dir_path, file_paths) tuples.
  """
  for dir_path, _, filenames in gfile.Walk(top):
    yield (dir_path, (os.path.join(dir_path, filename)
                      for filename in filenames)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:io_wrapper.py

示例2: _wav_files_and_labels

# 需要導入模塊: from tensorflow.python.platform import gfile [as 別名]
# 或者: from tensorflow.python.platform.gfile import Walk [as 別名]
def _wav_files_and_labels():
    """Get wav files path and labels as a dict object.

    Args:
        None
    Returns:
        result = { label:wav_file_list }
    """
    if not util.is_exists(FLAGS.wavfile_parent_dir):
        tf.logging.error("Can not find wav files at: {}, or you can download one at "
            "https://serv.cusp.nyu.edu/projects/urbansounddataset.".format(
                FLAGS.wavfile_parent_dir))
        exit(1)
    wav_files = []
    wav_labels = []
    label_idx = 0
    sub_dirs = [x[0] for x in gfile.Walk(FLAGS.wavfile_parent_dir)]
    # The root directory comes first, so skip it.
    is_root_dir = True
    for sub_dir in sub_dirs:
        if is_root_dir:
            is_root_dir = False
            continue
        extensions = ['wav']
        file_list = []
        dir_name = os.path.basename(sub_dir)
        if dir_name == FLAGS.wavfile_parent_dir:
            continue
        if dir_name[0] == '.':
            continue
        tf.logging.info("Looking for wavs in '" + dir_name + "'")
        for extension in extensions:
            file_glob = os.path.join(FLAGS.wavfile_parent_dir, dir_name, '*.' + extension)
            file_list.extend(gfile.Glob(file_glob))
        if not file_list:
            tf.logging.warning('No files found')
            continue
        if len(file_list) < 20:
            tf.logging.warning('WARNING: Folder has less than 20 wavs,'
                'which may cause issues.')
        elif len(file_list) > MAX_NUM_PER_CLASS:
            tf.logging.warning(
                'WARNING: Folder {} has more than {} wavs. Some wavs will '
                'never be selected.'.format(dir_name, MAX_NUM_PER_CLASS))
        # label_name = re.sub(r'[^a-z0-9]+', ' ', dir_name.lower())
        wav_files.extend(file_list)
        wav_labels.extend([label_idx]*len(file_list))
        label_idx += 1
    assert len(wav_files) == len(wav_labels), \
        'Length of wav files and wav labels should be in consistent.'
    return wav_files, wav_labels 
開發者ID:luuil,項目名稱:Tensorflow-Audio-Classification,代碼行數:53,代碼來源:audio_train.py

示例3: _load_device_dumps

# 需要導入模塊: from tensorflow.python.platform import gfile [as 別名]
# 或者: from tensorflow.python.platform.gfile import Walk [as 別名]
def _load_device_dumps(self, device_name, device_root):
    """Load `DebugTensorDatum` instances from the dump root of a given device.

    Populates a map {device_name: a list of `DebugTensorDatum`}, where the list
    is sorted by ascending timestamp.

    This sorting order reflects the order in which the TensorFlow executor
    processed the nodes of the graph. It is (one of many possible) topological
    sort of the nodes. This is useful for displaying tensors in the debugger
    frontend as well as for the use case in which the user wants to find a
    "culprit tensor", i.e., the first tensor in the graph that exhibits certain
    problematic properties, i.e., all zero values, or bad numerical values such
    as nan and inf.

    In addition, creates a map from node name to debug watches. In this Map,
    the key is the watched node name; the value is a dictionary.
    Of this dictionary, the key is the watched_output_slot.

    This method attempts to load the debug watches from the tensor dump files
    first, before loading the full set of debug watches from the partition
    graphs as done later. This is necessary because sometimes the partition
    graphs may not be available, e.g., when the run errors out.

    Args:
      device_name: (`str`) name of the device.
      device_root: (`str`) dump root directory of the given device.

    Raises:
      ValueError: If GraphDef for the device is not available.
    """

    self._dump_tensor_data[device_name] = []
    self._debug_watches[device_name] = collections.defaultdict(
        lambda: collections.defaultdict(set))

    for root, _, files in gfile.Walk(device_root):
      for f in files:
        if _is_graph_file(f):
          self._dump_graph_file_paths[device_name] = os.path.join(
              device_root, root, f)
        else:
          datum = self._dump_file_name_to_datum(root, f)
          self._dump_tensor_data[device_name].append(datum)
          self._debug_watches[device_name][datum.node_name][
              datum.output_slot].add(datum.debug_op)

    self._dump_tensor_data[device_name] = sorted(
        self._dump_tensor_data[device_name],
        key=lambda x: x.extended_timestamp)

    if self._dump_tensor_data[device_name]:
      self._t0s[device_name] = self._dump_tensor_data[device_name][0].timestamp
    else:
      self._t0s[device_name] = None 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:56,代碼來源:debug_data.py


注:本文中的tensorflow.python.platform.gfile.Walk方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。