Layer names for pretrained inception v3 model (ten

2019-03-29 14:25发布

问题:

This question already has an answer here:

  • List of tensor names in graph in Tensorflow 5 answers

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:

  1. To print all graph node names and construct graph using information only from node names. But node names are quite cryptic. Also connections between nodes are not so obvious, because of inception v3 architecture So without knowing the connections between nodes, this approach is like to break the code of enigma :)
  2. Then I tried to draw a graph of this model using own-written tool(get all inputs of given node(say, 'pool_3:0'), then get all inputs of each of inputs of 'pool_3:0', etc. This approach works for simple models. But when I tried to use it for inceptionv3 implementation from THE image recognition tutorial, I've got 16 GB of my RAM used, then 10 GB of swap, then I simply stopped looking under the hood. Maybe there are some cycles in graph(but how could it be if the network is feed-forward?)

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!

回答1:

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.