1
$\begingroup$

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)
$\endgroup$

1 Answer 1

1
$\begingroup$

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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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