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

耗尽温柔 提交于 2019-12-10 11:32:43

问题


I am doing image classification. Firstly I am feeding my images to my CNN model in Keras.

I want to add new features at the output of Flatten layer in keras and then feed it to the dense layer(s). How do I write a code for it?

Basically I am using Convolution for images and then at the end I want to add other features like Age Sex etc.

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

Before feeding flat as an input to the dense layer, I want to add a few features to flat. How do I do this?

Thanks for help!


回答1:


You just have to use the Concatenate layer to append those features to the flattened vector with a new Input layer:

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


来源:https://stackoverflow.com/questions/48473957/adding-new-features-to-the-output-of-flatten-layer-in-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!