im working on a neural network using Keras. Its an mlp(multi-layer perceptron). With 8 Neurons in the output layer. Is there a way I can access weights and biases of individual neurons of the output layer for every iteration?
2 Answers
$\begingroup$
$\endgroup$
1
I'm guessing you want something like this:
model.layers[-1].get_weights()
-
$\begingroup$ how can I use this function for every iteration? $\endgroup$ Commented Nov 1, 2019 at 8:48
$\begingroup$
$\endgroup$
The callback function can be used with model.layers[-1].get_weights()
to get weights per iteration.
weights=[]
getweights = LambdaCallback(on_epoch_end=lambda batch, logs: weights.append(model.layers[-1].get_weights()[1]))
model.fit(x, y, batch_size=5,epochs=10, callbacks=[getweights])
print(weights)
In the given code weights is a list which contains weight values for the first Neuron/class of output Layer.