# How to display the value of activation?

I have built my network and would like to see how the activation of a particular layer change after each epoch of training. For example, as code shown below, I want to see the activation values of "act_layer_1". What should I do so that I can see the activation values? Thanks in advance!

W1 = tf.get_variable('W1', [n_input,n_hidden_1], initializer = tf.contrib.layers.xavier_initializer(seed = 1))
b1 = tf.Variable(tf.constant(0.0, shape=[n_hidden_1], dtype=tf.float32), trainable=True, name='b1'),
act_layer_1 = tf.nn.relu(hidden_layer(x_image, W1) + b1)
drop_layer_1 = tf.nn.dropout(act_layer_1, keep_prob)


Although you have not made it clear in your code snippet but the activation output could be inside or outside a function:

• Outside Function : Just run
a = sess.run(act_layer_1)
print(a)

• Inside Function: You have to return the value of this activation bunched with other values you need to print and then again use sess.run() to get all the values and print the index which contains your value.

A longer but better in debugging would be to use tf.InteractiveSession(). More details can be found here:

How to print the value of a Tensor object in TensorFlow?

• I tried this and it does work. – Joshua Aug 16 '18 at 3:36
• @Joshua well then you can accept my answer by clicking on the tick :) – DuttaA Aug 16 '18 at 4:01
• Sorry, typo. It "doesn't" work out. – Joshua Aug 16 '18 at 4:41
• @Joshua it should work...can you provide the full code? – DuttaA Aug 16 '18 at 4:42
• Sure. By emailing you? – Joshua Aug 16 '18 at 4:49