Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras: Interpreting the output of get_weights()

Tags:

keras

I can't seem to find much documentation on how to interpret the output of get_weights() when running a neural network in Keras. From what I understand, the output is determined by the structure of the network. Therefore, I paste a simplified version of the structure of my network below:

model.add(Dense(5, input_dim=2, activation = linear, use_bias=True, kernel_initializer=Orthogonal))
model.add(Dense(1, use_bias=True))
model.compile(loss='mae', optimizer='adam')

The output of get_weights() after training is:

     [array([[ 0.79376745,  0.79879117,  1.22406125,  1.07782006,  1.24107373],
           [ 0.88034034,  0.88281095,  1.13124955,  0.98677355,  1.14481246]], dtype=float32), 
      array([-0.09109745, -0.09036621,  0.0977743 , -0.07977977,  0.10829113], dtype=float32), 
      array([[-0.72631335],
           [-0.38004425],
           [ 0.62861812],
           [ 0.10909595],
           [ 0.30652359]], dtype=float32), 
      array([ 0.09278722], dtype=float32)]

There are a total of four arrays. What does each represent? Thanks!

like image 630
Agrippa Avatar asked Oct 18 '17 18:10

Agrippa


People also ask

What does Get_weights return?

get_weights method Returns the current weights of the layer, as NumPy arrays. The weights of a layer represent the state of the layer.


1 Answers

  • Weights for the first layer (2 inputs x 5 units)
  • Biases for the first layer (5 units)
  • Weights for the second layer (5 inputs x 1 unit)
  • Biases for the second layer (1 unit)

You can always get by layer too:

for lay in model.layers:
    print(lay.name)
    print(lay.get_weights())
like image 91
Daniel Möller Avatar answered Oct 16 '22 11:10

Daniel Möller