user3284804
user3284804

Reputation: 121

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

How to make a not fully connected graph in Keras? I am trying to make a network with some nodes in input layer that are not connected to the hidden layer but to the output layer. Is there any way to do this easily in Keras? Thanks!

Upvotes: 5

Views: 1518

Answers (1)

nemo
nemo

Reputation: 57739

Yes, this 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 is better at explaining what merge does in detail. The general idea of multiple inputs and the functional model can be read here.

Upvotes: 5

Related Questions