我想构建一个 CNN 模型,该模型需要 3 个连续图像而不是一个,因此输入的形状为: (3,height, width, channels=3) :
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, Dropout, Dense,
Flatten,Convolution2D
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam
def build_cnn_model(frames_number,height,width,channel, nb_actions):
model = Sequential()
model.add( Input((frames_number,height,width,channel),name='Input') )
model.add( Conv2D(96, (3,3), strides=(4,4), activation='relu', name='Conv2D_1',
input_shape = (frames_number,height,width,channel) ) )
model.add( MaxPooling2D((2, 2), name='MaxPooling2D_1') )
model.add( Dropout(0.2,name='Dropout_1'))
model.add( Conv2D(192, (3, 3), activation='relu', name='Conv2D_2') )
model.add( MaxPooling2D((2, 2), name='MaxPooling2D_2') )
model.add( Dropout(0.2, name='Dropout_2'))
model.add( Flatten(name='Flatten_1'))
model.add( Dense(1500, activation='relu', name='Dense_1') )
model.add( Dropout(0.5, name='Dropout_DNN_1'))
model.add(Dense(nb_actions, activation='linear', name='Output') )
return model
model = build_cnn_model(3,220,300,3,6)
这个结构对我来说似乎是逻辑,但我得到了:
ValueError: Input 0 of layer Conv2D_1 is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 3, 210, 160, 3]
请注意,我知道也可以更改数据形状,以便可以将 3 张图像放入 3*3 通道的单个图像中。但我无法在我的程序中应用该解决方案。我想传递(3,高度,宽度,3)的输入。