Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras - is it possible to view the weights and biases of models in Tensorboard

I just got started with Keras and built a Q-learning example program. I created a tensorboard callback and I include it in the call to model.fit, but the only things that appear in TensorBoard are the scalar summary for the loss and the network graph. Interestingly, if I open up the dense layer in the graph, I see a little summary icon labeled "bias_0" and one labeled "kernel_0", but I don't see these appearing in the distributions or histograms tabs in TensorBoard like I did when I built a model in pure tensorflow.

Do I need to do something else to enable these in Tensorboard? Do I need to look into the details of the model that Keras produces and add my own tensor_summary() calls?

like image 201
Ocie Mitchell Avatar asked May 09 '17 00:05

Ocie Mitchell


2 Answers

You can get the weights and biases per layer and for the entire model with .get_weights().

For example if the first layer of your model is the dense layer for which you would like to have your weights and biases, you can get them with:

weights, biases = model.layers[0].get_weights()
like image 101
Wilmar van Ommeren Avatar answered Oct 06 '22 07:10

Wilmar van Ommeren


I debugged this and found that the problem was I was not providing any validation data when I called fit(). The TensorBoard callback will only report on the weights when validation data is provided. That seems a bit restrictive, but I at least have something that works.

like image 28
Ocie Mitchell Avatar answered Oct 06 '22 09:10

Ocie Mitchell