简体   繁体   中英

keras ImageDataGenerator.flow with color_mode

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

You can't do it as part of .flow because that assumes you already have loaded an prepared your images into a 4D tensor. You can use the load_img function which the .flow_from_directory uses that actually consumes the color_mode argument:

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

This is from the flow_from_directory code. You can use this function to load your images and then call .flow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM