我正在尝试连接2个CNN。这是代码:
input1 = keras.layers.Input(shape=(64,64,1), name="camera")
input2 = keras.layers.Input(shape=(64,64,1), name="lidar")
# First branch
input1_features = keras.layers.Lambda(lambda x: x / 255.0)(input1)
input1_features = keras.layers.Conv2D(16, (3, 3), strides=(4, 4), padding = 'same', activation='relu')(input1_features)
input1_features = keras.layers.Conv2D(32, (2, 2), strides=(2, 2), padding = 'same' ,activation='relu')(input1_features)
input1_features = keras.layers.Flatten()(input1_features)
# Second branch
input2_features = keras.layers.Lambda(lambda x: x / 255.0)(input2)
input2_features = keras.layers.Conv2D(16, (3, 3), strides=(4, 4), padding = 'same', activation='relu')(input2_features)
input2_features = keras.layers.Conv2D(32, (2, 2), strides=(2, 2), padding = 'same' ,activation='relu')(input2_features)
input2_features = keras.layers.Flatten()(input2_features)
merged = keras.layers.Concatenate(axis=1)([input1_features, input2_features])
hidden1 = keras.layers.Dense(128, activation='relu')(merged)
hidden2 = keras.layers.Dense(256, activation='relu')(hidden1)
output = keras.layers.Dense(action_space, activation='softmax', name="action")(hidden2)
nn = keras.models.Model([input1, input2], output)
nn.compile(loss={"camera" : "mse",
"lidar" : "mse"},
optimizer=Adam(lr=LEARNING_RATE))
ValueError:密集层4的输入0与该层不兼容:预期输入形状的轴-1的值为4096,但接收到形状为[32,512]的输入
这是预测代码:
np.argmax(dqn.predict([camera,lidar]))
我已经仔细检查了两个图像的形状,它们分别是(64,64,1)。
我正在尝试编写一个nn,它将2张图像作为输入并输出9个动作之一。
我已经尝试使用Dense中的所有参数,但一无所获。这是该模型的摘要: