ImageDataGenerator默认的flow_from_directory函数中有个color_mode设置,我看文献中只支持‘gray'和'rgb',但我现在要处理的图像是RGBD的4通道图像,如何设置呢?求大师指点。
我尝试着将color_mode设置为'rgb',但是在第一层卷积层的输入数据类型,设置的是(width,height,4)的四通道格式,运行的时候出错了,提示如果我的color_mode设置成了‘rgb',那么自动生成batch的时候,依旧是会变为3通道格式。具体如下:
在flow_from_directory中的color为‘rgb'
train_generator = train_datagen.flow_from_directory(
directory= train_dir, # this is the target directory
target_size=(200, 200), # all images will be resized to 200x200
classes= potato_class,
batch_size=60,
color_mode= 'rgb',
class_mode='sparse')
在卷基层的输入input_shape中设置为4通道
model = Sequential() # CNN构建
model.add(Convolution2D(
input_shape=(200, 200, 4),
# input_shape=(1, Width, Height),
filters=16,
kernel_size=3,
strides=1,
padding='same',
data_format='channels_last',
name='CONV_1'
))
运行后的错误提示如下:
ValueError: Error when checking input: expected CONV_1_input to have shape (None, 200, 200, 4) but got array with shape (60, 200, 200, 3)
怎样才能让keras接受4通道图像呢?我在stackOverflow中看到有人留言说4通道是支持的,但是我没有找到代码。