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

标签 python tensorflow keras

我正在尝试通过使用 ImageDataGenerator 并将自定义函数传递给 preprocessing_function 参数对我的图像应用一些裁剪操作。然而,根据 Keras 文档,此函数只会在图像调整大小后运行:

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)。再次来自文档:

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

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

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

在我的案例中,裁剪已调整大小的图像会产生错误的结果。因此,我正在寻找一种方法,以防止调整大小发生或仅在应用我的自定义预处理功能后才发生。如果不编写整个自定义数据生成器,这可能吗?

最佳答案

对于 ImageDataGenerator 的当前实现,这是不可能的。 loading image 时会调整图像大小,而预处理函数是从standardize几个步骤调用的later .

在加载期间不调整大小也不是一个选项,因为迭代器 pre-allocates一个批处理的数组,需要知道它的形状。

关于python - Keras:如何在使用带有 flow_from_dataframe/flow_from_directory 的 ImageDataGenerator 时禁用图像大小调整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54914906/

相关文章:

tensorflow - 如何从源代码更新 Tensorflow

python - 如何在使用 DNNCLassifier 时可视化嵌入 - Tensorflow

python - 连接 numpy 数组时出现值错误

tensorflow - 具有交叉熵的像素级 softmax 用于多类分割

python - 使用 PyTesser 破解简单的验证码

python - 你如何用 pyparsing 解析文字星号?

python - Tensorflow 不使用 GPU,发现 xla_gpu 不是 gpu

TensorFlow Graph 到 Keras 模型?

Python语言API

python - 错误 : [Errno -2] Name or service not known