Tensorflow:读取各个目录中的jpg

标签 tensorflow

我想读取存储在另一个目录('all_image_dir')内的子目录中的所有 jpg。子目录名称如“001”、“002”等。

读取某个目录中的所有jpg不是问题,例如'all_image_dir/001,使用:

filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once('all_image_dir/001/*.jpg')) 

要访问所有目录中的所有 jpg,我尝试了如下操作:

 filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once('all_image_dir/*/*.JPG')) 

但这不起作用... - 我该怎么做?

最佳答案

tf.train.match_filenames_once 的 pattern 模式参数相当有限。对于您的特定情况,假设您的子目录为 001002、... 020。您可以执行以下操作来达到与 'all_image_dir/*/*.JPG' 相同的效果:

在终端中分别获取001、002等文件

ln -s folder1 1
ln -s folder2 2
...
ln -s folder20 20

然后:

all_files = [tf.train.match_filenames_once(
    'all_image_dir/%03d/*' % x) for x in range(20)]
# Concatenate the list of all the files before passing to string_input_producer
filename_queue = tf.train.string_input_producer(tf.concat(all_files, 0))

关于Tensorflow:读取各个目录中的jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38354537/

相关文章:

python - tensorflow 线性回归的pytorch等价物是什么?

python - 什么是 DepthwiseConv2D 和 SeparableConv2D?它与keras中的普通Conv2D层有何不同?

tensorflow - 在 TensorFlow Federated 中使用 update_struct 函数时出错

python - Tensorflow:如何在张量板上查看检查点?

python - 如何使用自定义 CTC 层正确保存和加载模型(Keras 示例)

tensorflow - Keras 数据生成器预测相同数量的值

tensorflow - 如何评估 tensorflow 估计器每个时期的测试数据集

tensorflow - 将 softmax 与 tf.nn.weighted_cross_entropy_with_logits 结合使用

python - 值错误 : cannot reshape array of size 2352 into shape (1, 28,28)

macos - 找不到-ltensorflow