How to show hidden layer outputs in Tensorflow

一世执手 提交于 2019-12-05 09:39:54

When you run sess.run(layer1), you're telling tensorflow to compute the value of layer1 tensor, which is ...

layer1 = graph.get_tensor_by_name("lstm_1_1/kernel:0")

... according to your definition. Note that LSTM kernel is the weights variable. It does not depend on the input, that's why you get the same result with sess.run(layer1, feed_dict={input:X_test}). It's not like tensorflow is computing the output if the input is provided -- it's computing the specified tensor(s), in this case layer1.

When does input matter then? When there is a dependency on it. For example:

  • sess.run(output). It simply won't work without an input, or any tensor that will allow to compute the input.
  • The optimization op, such as tf.train.AdapOptimizer(...).minimize(loss). Running this op will change layer1, but it also needs the input to do so.

Maybe you can try TensorBoard and examine your graph to find the outputs of the hidden layers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!