python - 带有 color_mode 的 keras ImageDataGenerator.flow

标签 python image image-processing keras deep-learning

我正在使用python和keras,并希望使用keras图像预处理,我的一些图像是rgb,而一些是灰度,我需要读取所有这些图像并将灰度图像的尺寸更改为x,x, 3 或处理它们,并希望将其作为 .flow 函数的一部分来执行,就像我可以将 color_mode 与 .flow_from_directory 一起使用一样,可以将其设置为 rgb 并将所有图像读取为 rgb,即使它们是灰度的, 这可能吗?

最佳答案

您不能将其作为 .flow 的一部分来执行,因为这假设您已经将准备好的图像加载到 4D 张量中。您可以使用 load_img .flow_from_directory 使用的函数实际使用 color_mode 参数:

img = load_img(os.path.join(self.directory, fname),
               color_mode=self.color_mode,
               target_size=self.target_size,
               interpolation=self.interpolation)

这来自flow_from_directory代码。您可以使用此函数加载图像,然后调用 .flow

关于python - 带有 color_mode 的 keras ImageDataGenerator.flow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52352678/

相关文章:

Python webbrowser.open() 打开 Chrome 浏览器

javascript - 图像的正则表达式未返回预期值

c# - 从 PersistentDataPath 加载图像

go - 如何循环旋转图像以在 golang 中创建 GIF?

python - 如何计算细胞核数量?

Python - 从元组 CSV 文件中删除大括号和逗号

python - 如何在 Ubuntu 11.10 中使用 Python 2.6?

python - HTML 火狐书签

html - 如何使网站图像和幻灯片看起来像是设备屏幕?

c# - 为什么精确的图像没有精确的描述符?