Adding new features to the output of Flatten() lay

2019-05-18 20:18发布

问题:

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)