我正在使用带有keras的python,并且希望使用keras图像预处理,我的一些图像是rgb而有些是灰度的,我需要读取所有图像并将灰度图像的尺寸更改为x,x, 3或处理它们,并希望将其作为.flow函数的一部分,就像我可以将color_mode与.flow_from_directory一起使用一样,可以将其设置为rgb并将所有图像读取为rgb,即使它们是灰度的, 有可能吗?
答案 0 :(得分:2)
您不能将其作为.flow
的一部分,因为这假定您已经将准备好的图像加载到4D张量中。您可以使用.flow_from_directory
使用的load_img函数,该函数实际上消耗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
。