# how to access weights of individual Neurons in the output layers in MLPs?

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?

I'm guessing you want something like this:

model.layers[-1].get_weights()

• how can I use this function for every iteration? – imtiaz ul Hassan Nov 1 '19 at 8:48

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.