我在使用Keras开发一个国际象棋AI时,遇到在堆叠卷积层时出现错误的问题,因为它指出形状与前一池化层不一致。错误信息如下所示:
Input 0 of layer conv2d is incompatible with the layer: expected axis -1 of input shape to have value 12 but received input with shape [None, 3, 3, 2]
可复现的代码段:
回答:
你需要创建另一个卷积层
conv1 = Conv2D(2, 3, activation='relu')conv2 = Conv2D(2, 3, activation='relu')pooling = MaxPooling2D(pool_size=(2, 2), strides=None, padding="valid", data_format=None,)flatten = Flatten(data_format=None)board_inputs = Input(shape=(8, 8, 12))x = conv1(board_inputs)x = pooling(x)x = conv2(x)x = flatten(x)output = Dense(12)(x)model = Model(inputs=board_inputs, outputs=output, name="chess_ai_v3")model.summary()