【问题标题】:What does '/*/*' mean in tensorflow's Dataset.list_files function?tensorflow 的 Dataset.list_files 函数中的“/*/*”是什么意思?
【发布时间】:2020-12-13 12:15:13
【问题描述】:

我正在使用 Tflite。我正在学习如何量化为 INT8。 我正在使用 Colab 教程。 “flowers_dir”是一个包含 5 个文件夹的文件夹(每个文件夹包含不同类型的花)。 '/*/*' 是什么意思?我的直觉告诉我这是调用每个文件夹的内容。不确定。有没有类似解释它的“教程”?

# A generator that provides a representative dataset
def representative_data_gen():
  dataset_list = tf.data.Dataset.list_files(flowers_dir + '/*/*')
  for i in range(100):
    image = next(iter(dataset_list))
    image = tf.io.read_file(image)
    image = tf.io.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, [IMAGE_SIZE, IMAGE_SIZE])
    image = tf.cast(image / 255., tf.float32)
    image = tf.expand_dims(image, 0)
    yield [image]

【问题讨论】:

  • 文件路径中的通配符
  • flowers_dir中深度为2的子目录下的所有文件
  • 顺便说一句——代码应该以文本的形式提供,而不是图像。请参阅Meta Stack Exchange 上的Why not upload images of code/errors when asking a question?。代码图像不可搜索;它们不能被复制/粘贴(这使得重现问题变得不必要地困难);模棱两可的字体无法纠正;屏幕阅读器等辅助工具无法与它们一起使用;对于更高的屏幕分辨率或其他未来的显示技术,它们不是面向未来的;等

标签: python python-3.x tensorflow tensorflow-datasets


【解决方案1】:

来自Dataset.list_fileshttps://www.tensorflow.org/api_docs/python/tf/data/Dataset#list_files 的文档:

file_pattern 参数应该是少数 glob 模式。如果您的文件名已经被通配,请改用 Dataset.from_tensor_slices(filenames),因为使用 list_files 重新通配每个文件名可能会导致远程存储系统性能不佳。

所以,我们知道您拥有的是 glob 模式。什么是全局模式?谷歌救援:https://en.wikipedia.org/wiki/Glob_(programming)。如其中所述:

* 是一个通配符,代表“任意字符串”

...所以,/*/* 意味着您有一个可以包含任何字符串的目录,我们在其中查找 other 文件,这些文件的名称又可以是任何字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    相关资源
    最近更新 更多