Models: How to get the intermediate layers output of pretrained model?

Created on 4 Sep 2018  路  4Comments  路  Source: tensorflow/models

In tensorflow, Resnet101 has 5 conv layers . If ip is of 960960, then conv1, pool2,conv3-3, conv5-3 has resolution 480480,240240,120120, 60*60.
Now i want to get intermediate layer outputs @conv1,@pool2,@conv3-3, @conv5-3. How to get the intermediate layers output of pretrained model in tensorflow.

Kindly help

Most helpful comment

any way to do this using the keras APIs?

All 4 comments

In the session run you can pass the name of the layer (you can get the heirarchy using Tensorboard visualization of the graph) .

For example:
feat_0=detection_graph.get_tensor_by_name('FeatureExtractor/MobilenetV2/expanded_conv_13/expansion_output:0')
feat_1=detection_graph.get_tensor_by_name('FeatureExtractor/MobilenetV2/Conv_1/Relu6:0')

  • FeatureExtractor/MobilenetV2/expanded_conv_13/expansion_output:0 obtained from TensorBoard
  • the " :0 " is important. It specifies the output tensor.

(Feat_0,Feat_2) = sess.run( [feat_0,feat_1], feed_dict={image_tensor: img_expanded})

Thanks Sukanya-Kudi for the answer, I think that should work.

Thanks sukanya for your fruitful suggestions

any way to do this using the keras APIs?

Was this page helpful?
0 / 5 - 0 ratings