简体   繁体   English

Keras:如何在使用带有 flow_from_dataframe / flow_from_directory 的 ImageDataGenerator 时禁用调整图像大小?

[英]Keras: how to disable resizing of images when using an ImageDataGenerator with flow_from_dataframe / flow_from_directory?

I am trying to apply some cropping operations on my images by using an ImageDataGenerator and passing a custom function to the preprocessing_function parameter .我试图通过使用 ImageDataGenerator 并将自定义函数传递给preprocessing_function参数来对我的图像应用一些裁剪操作。 However, according to the Keras docs, this function will only run after the images are already resized:但是,根据 Keras 文档,此功能只会在图像已调整大小后运行:

preprocessing_function : function that will be implied on each input. preprocessing_function :将隐含在每个输入上的函数。 The function will run after the image is resized and augmented.该函数将在图像调整大小和增强后运行。

Now I would like to disable resizing, however the target_size parameter defaults to (256,256) if no value is provided.现在我想禁用调整大小,但是如果没有提供值,则 target_size 参数默认为 (256,256)。 Again from the docs:再次来自文档:

target_size : Tuple of integers (height, width), default: (256, 256). target_size :整数元组(高度、宽度),默认值:(256, 256)。 The dimensions to which all images found will be resized.找到的所有图像的尺寸将被调整。

I've been trying to set the target_size parameter to None , however this results in an error:我一直在尝试将target_size参数设置为None ,但这会导致错误:

TypeError: 'NoneType' object cannot be interpreted as an integer

Cropping an already resized image yields wrong results in my case.在我的情况下,裁剪已经调整大小的图像会产生错误的结果。 Hence I am looking for a way, to prevent either the resizing to happen at all or for it to only happen after my custom preprocessing function has been applied.因此,我正在寻找一种方法,以防止调整大小发生或仅在应用我的自定义预处理功能后发生。 Is this possible without writing an entire custom data generator?如果不编写整个自定义数据生成器,这可能吗?

With the current implementation of ImageDataGenerator it is impossible.使用 ImageDataGenerator 的当前实现是不可能的。 Image resizing happens while loading image , while preprocessing function is called from standardize few steps later .图像大小在加载图像时发生,而预处理函数在几步之后standardize调用。

Not to resize during loading is also not an option, since iterator pre-allocates the array for a batch and needs to know its shape.在加载期间不调整大小也不是一种选择,因为迭代器预先分配了一个批次的数组并且需要知道它的形状。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 keras ImageDataGenerator flow_from_dataframe 时,验证集仅从一类获取图像 - Validation set only gets images from one class when using keras ImageDataGenerator flow_from_dataframe 如何在 keras 中使用 ImageDataGenerator 和 flow_from_directory 保存增强图像 - How to save augmented images using ImageDataGenerator and flow_from_directory in keras Keras ImageDataGenerator 方法 flow_from_directory - Keras ImageDataGenerator method flow_from_directory Keras flow_from_dataframe 提供 0 张图片 - Keras flow_from_dataframe gives 0 images 使用 ImageDataGenerator 和 flow_from_directory 时,Keras 中的数据增强是否应用于验证集 - Is data augmentation in Keras applied to the validation set when using ImageDataGenerator and flow_from_directory Keras ImageDataGenerator和flow_from_directory class_mode ='input' - Keras ImageDataGenerator and flow_from_directory class_mode='input' 如何在keras中使用flow_from_dataframe输入多个图像? - How to input multiple images with flow_from_dataframe in keras? Keras flow_from_dataframe - Keras flow_from_dataframe 使用 ImageDataGenerator 和 flow_from_directory 时如何使用来自 TensorHub 的迁移学习和自定义图像大小 - How to use transfer learning from TensorHub with custom image sizes when using ImageDataGenerator and flow_from_directory 如何使用 ImageDataGenerator().flow_from_dataframe 进行扩充? - How to use augmentations with ImageDataGenerator().flow_from_dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM