The task is to get per-layer output of a pretrained cnn inceptionv3 model. For example I feed an image to this network, and I want to get not only its output, but output of each layer(layer-wise).
In order to do that, I have to know names of each layer output. It's quite easy to do for last and pre-last layer:
sess.graph.get_tensor_by_name('pool_3:0')
sess.graph.get_tensor_by_name('softmax:0')
(names pool_3:0 and softmax:0 are listed in sources related to the model)
But what if I want to get output of not only last and pre-last layer, but also pre-pre-last, pre-pre-pre-last, etc, output of any layer of this model?
Then I have to know layer names. A similar question has been asked on stackoverflow, but there are only names for pre-last and last layers, which are also available in comments in the sources('pool_3:0', 'softmax:0')
The obvious way to get names is to draw a graph of the model. But it's not the case because graph-drawing tool simply crashes. Also there is an issue related to this.
I also tried:
So, maybe somebody who's participated in this pre-trained model implementation & 'shipping' is reading stackoverflow.
Or maybe somebody has already got layer-wise names for this model. Please share it with me and ml community. Thanks in advance!
The base question has already been asked (and answered) in List of tensor names in graph in Tensorflow
To answer your concern with your approach (2) - that does work (i've done it). If I had to guess, you probably don't use a dictionary-like structure to store the nodes, so if multiple nodes get their input from the same node (like it happens a lot in the inception model), you insert that input node multiple times in your list of things to store / visit. If you take care to visit each node only once, that should run basically instantly without memory problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With