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$
2
$\begingroup$

I'm guessing you want something like this:

model.layers[-1].get_weights()
| improve this answer | |
$\endgroup$
  • $\begingroup$ how can I use this function for every iteration? $\endgroup$ – imtiaz ul Hassan Nov 1 '19 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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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