batuman
batuman

Reputation: 7314

Extract layer's output at Tensorflow

How to get individual layer's output tensor in Tensorflow. Say after TF model has passed through with input image, I'd like to have some of the layers' outputs by name.

How can I have it?

Upvotes: 0

Views: 366

Answers (1)

arcticriki
arcticriki

Reputation: 72

Saying that you named your layer with name="output" you can get the specific output with the following.

output = graph.get_tensor_by_name('output:0')

where graph is the default graph, obtained with graph = tf.get_default_graph(). However, note that output is a tensor. I imagine that you would like to do some manipulations/visualizations of the output. In that case, you need to run this command within a Session. Like this:

with tf.Session() as sess:
    output = graph.get_tensor_by_name('output:0')
    output_values = sess.run(output, feed_dict={x: input})

Upvotes: 2

Related Questions