【问题标题】:Why are my images not saving? Using TensorFlow Keras.preprocessing.image.directoryIterator为什么我的图像没有保存?使用 TensorFlow Keras.preprocessing.image.directoryIterator
【发布时间】:2020-12-19 23:43:47
【问题描述】:

我对使用 tensorflow 和使用 CNN 非常陌生。我正在尝试加载我的图像数据集并调整每个图像的大小和灰度。我正在阅读有关 TensorFlow Keras.preprocessing.image.directoryIterator 的文档。我试过了(下面的代码),它找到了我所有的图像,但实际上并没有保存它们或对图像进行任何修改?难道我做错了什么?我自己有这段代码,所以我不确定是否需要设置其他任何东西才能完成这项工作。任何帮助表示赞赏!不幸的是,互联网上没有太多文档或帮助:(

注意:我已排除包含图像的本地文件路径 - 但我的代码中确实有合法路径。另外,save_to_dir 参数,我不确定它是只是目录名还是完整的文件路径,但我已经尝试了这两种方法,但它们都不起作用。

image.DirectoryIterator(
'LOCAL FILE PATH', image_data_generator, target_size=(170, 170),
color_mode ='grayscale', classes =['Face', 'NonFace'], class_mode ="categorical",
batch_size=5, shuffle=True, seed=None, data_format ='channels_first',
save_to_dir = 'Test', save_prefix='Test_', save_format ='jpg',
follow_links=False, subset=None, interpolation='nearest', dtype=None)

【问题讨论】:

    标签: python image tensorflow keras image-preprocessing


    【解决方案1】:

    您需要触发您创建的生成器Iterator。

    以下是将文件保存在所需目录中的代码。

    import tensorflow as tf
    from tensorflow.keras.preprocessing.image import ImageDataGenerator 
    
    image_data_generator = ImageDataGenerator() 
    
    image = tf.keras.preprocessing.image.DirectoryIterator(
    '/content/Images/', image_data_generator, target_size=(170, 170),
    color_mode ='grayscale', classes =['Face', 'NonFace'], class_mode ="categorical",
    batch_size=5, shuffle=True, seed=None, data_format ='channels_first',
    save_to_dir = '/content/Test/', save_prefix='Test_', save_format ='jpg',
    follow_links=False, subset=None, interpolation='nearest', dtype=None)
    
    image.next() # This line will trigger the execution of Iterator. 
    

    【讨论】:

      猜你喜欢
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      相关资源
      最近更新 更多