Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using summary with tf slim or tf layers

Tags:

tensorflow

I cannot not find how to add a summary to visualize weights for networks which have been defined with tf.contrib.slim or tf.contrib.layers.

For instance, if I have:

net = slim.conv2d(net, ...)

How can I add the weights and bias into a summary ?

Edit: I just saw that I could use tf.contrib.layers.summarize_collection. That probably works for what I want to do.

like image 862
Conchylicultor Avatar asked Feb 17 '17 19:02

Conchylicultor


1 Answers

Here is the solution I found after deeper investigation, in case someone has the same problem than me.

For tf.contrib.slim, (deprecated) the weights are added to the collection tf.GraphKeys.TRAINABLE_VARIABLES which can be visualized with:

tf.contrib.layers.summarize_collection(tf.GraphKeys.TRAINABLE_VARIABLES)

For tf.contrib.layers, there are some convenience methods

tf.contrib.layers.summarize_weights()  # tf.GraphKeys.WEIGHTS
tf.contrib.layers.summarize_biases()  # tf.GraphKeys.BIASES
# For tf >= 1.3:
tf.contrib.layers.summarize_tensors()

To have a better control on which variables add, it's possible by customizing the code of summarize_collection.

like image 174
Conchylicultor Avatar answered Sep 17 '22 17:09

Conchylicultor