2
$\begingroup$

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?

$\endgroup$
1

2 Answers 2

2
$\begingroup$

I'm guessing you want something like this:

model.layers[-1].get_weights()
$\endgroup$
1
  • $\begingroup$ how can I use this function for every iteration? $\endgroup$ Commented Nov 1, 2019 at 8:48
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.