How to connect some nodes directly to the output layer in Keras

How to make an incompletely connected graph in Keras? I am trying to create a network with some nodes at the input level that are not associated with the hidden layer, but with the output level. Is there a way to make this easy in Keras? Thank!

+4
source share
1 answer

Yes it is possible. The easiest way to do this is to specify two inputs:

in_1 = Input(...)
in_2 = Input(...)

hidden = Dense(...)(in_1)

# combine secondary inputs and hidden outputs
in_2_and_hidden = merge([in_2, hidden], mode='concat')

# feed combined vector to output
output = Dense(...)(in_2_and_hidden)

The documentation better explains that mergein detail. The general idea of ​​several inputs and functional models can be read here .

+4
source

Source: https://habr.com/ru/post/1656290/


All Articles