Keras:在将ImageDataGenerator与flow_from_dataframe/flow_from_directory结合使用时,如何禁用图像大小调整? [英] Keras: how to disable resizing of images when using an ImageDataGenerator with flow_from_dataframe / flow_from_directory?

查看:114
本文介绍了Keras:在将ImageDataGenerator与flow_from_dataframe/flow_from_directory结合使用时,如何禁用图像大小调整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用ImageDataGenerator并将自定义函数传递给preprocessing_function参数对我的图像进行一些裁剪操作.但是,根据Keras文档,此功能仅在调整图像大小后才能运行:

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 . However, according to the Keras docs, this function will only run after the images are already resized:

preprocessing_function :每个输入将隐含的函数. 该功能将在调整图像大小和扩大后运行.

preprocessing_function: function that will be implied on each input. The function will run after the image is resized and augmented.

现在,我想禁用调整大小,但是,如果未提供任何值,则target_size参数默认为(256,256).再次来自文档:

Now I would like to disable resizing, however the target_size parameter defaults to (256,256) if no value is provided. Again from the docs:

target_size :整数元组(高度,宽度),默认值:(256,256). 找到的所有图像的尺寸将被调整为大小.

target_size: Tuple of integers (height, width), default: (256, 256). The dimensions to which all images found will be resized.

我一直试图将target_size参数设置为None,但这会导致错误:

I've been trying to set the target_size parameter to None, however this results in an error:

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?

推荐答案

使用ImageDataGenerator的当前实现是不可能的.图像调整大小发生在加载图像,同时从standardize几个步骤调用预处理功能

With the current implementation of ImageDataGenerator it is impossible. Image resizing happens while loading image, while preprocessing function is called from standardize few steps later.

在加载过程中不调整大小也不是一种选择,因为迭代器

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.

这篇关于Keras:在将ImageDataGenerator与flow_from_dataframe/flow_from_directory结合使用时,如何禁用图像大小调整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆