本文整理汇总了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))
示例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
示例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