向 Keras 中 Flatten() 层的输出添加新功能

Adding new features to the output of Flatten() layer in Keras

我在做图像分类。首先,我将我的图像输入到 Keras 中的 CNN 模型中。

我想在 keras 的 Flatten 层的输出端添加新特征,然后将其提供给密集层。如何为其编写代码?

基本上我对图像使用卷积,然后在最后我想添加其他特征,如年龄性别等

max_pool_final = MaxPooling2D(pool_size=(2,2))(conv_final)
flat = Flatten()(max_pool_final)
dense = Dense(128)(flat)

在将 flat 作为输入输入到密集层之前,我想向 flat 添加一些特征。我该怎么做?

感谢帮助!

您只需使用 Concatenate 层将这些特征附加到具有新输入层的展平向量中:

otherInp = Input(shape = (n_features, ))
concatenatedFeatures = Concatenate(axis = 1)([flat, otherInp])
dense = Dense(128)(concatenatedFeatures)