预训练的Inception v3模型的图层名称(tensorflow) [英] Layer names for pretrained inception v3 model (tensorflow)

查看:315
本文介绍了预训练的Inception v3模型的图层名称(tensorflow)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务是获取预先训练的cnn的每层输出inceptionv3 模型. 例如,我将图像馈送到该网络,不仅要获得其输出,还要获得每个层的输出(逐层).

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')

(与模型相关的来源中列出了名称pool_3:0和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?

然后我必须知道图层名称.有人问过类似的问题 在stackoverflow上,但是只有前最后一层和最后一层的名称,这些名称也可以在源代码中的注释中找到("pool_3:0","softmax:0")

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.

我也尝试过:

  1. 仅打印节点名称中的信息即可打印所有图形节点名称并构造图形.但是节点名称是非常隐秘的.此外,由于 inception v3体系结构,节点之间的连接并不是很明显在节点之间,这种方法就像破坏enigma的代码:)
  2. 然后,我尝试使用自己编写的工具绘制此模型的图形(获取给定节点的所有输入(例如'pool_3:0'),然后获取'pool_3:0'的每个输入的所有输入,这种方法适用于简单的模型,但是当我尝试将其用于图像识别教程中的inceptionv3实现时,我已经使用了16 GB的RAM,然后使用了10 GB的交换空间,然后我只是停止了查找.也许图中有一些循环(但是如果网络是前馈,怎么可能?)
  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?)

因此,也许有人参与了此预训练的模型实施和测试; 运送"正在读取stackoverflow.

So, maybe somebody who's participated in this pre-trained model implementation & 'shipping' is reading stackoverflow.

或者也许有人已经为该模型获得了分层名称. 请与我和ml社区分享.预先感谢!

Or maybe somebody has already got layer-wise names for this model. Please share it with me and ml community. Thanks in advance!

推荐答案

基本问题已经在要回答您对方法(2)的担忧-确实可行(我已经做到了).如果我不得不猜测,您可能不使用类似字典的结构来存储节点,因此,如果多个节点从同一个节点获取输入(就像在初始模型中发生的很多),则可以插入该输入节点在您要存储/访问的事物列表中多次.如果您只照顾每个节点一次,那么基本上应该立即运行,而不会出现内存问题.

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.

这篇关于预训练的Inception v3模型的图层名称(tensorflow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆