Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 402
user3284804 Avatar asked Sep 29 '16 23:09

user3284804


People also ask

What is output layer?

“ - The output layer is the final layer in the neural network where desired predictions are obtained. There is one output layer in a neural network that produces the desired final prediction. It has its own set of weights and biases that are applied before the final output is derived.

How many nodes should a neural network have?

Input layer should contain 387 nodes for each of the features. Output layer should contain 3 nodes for each class. Hidden layers I find gradually decreasing the number with neurons within each layer works quite well (this list of tips and tricks agrees with this when creating autoencoders for compression tasks).


1 Answers

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.

like image 136
nemo Avatar answered Nov 10 '22 20:11

nemo