如何获取要在iOS示例应用程序中使用的图层名称? (Tensorflow) [英] How do I obtain the layer names for use in the iOS sample app? (Tensorflow)

查看:452
本文介绍了如何获取要在iOS示例应用程序中使用的图层名称? (Tensorflow)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Tensorflow的新手,我正在尝试使用初始v3网络训练某些内容,以便在iPhone应用中使用。我设法将我的图形导出为协议缓冲文件,手动删除丢失节点(正确,我希望),并将该.pb文件放在我的iOS项目中,但现在我收到以下错误:

 运行模式失败:未找到:FeedInputs:无法找到Feed输入

这似乎表明我的 input_layer_name output_layer_name 变量在iOS应用程序配置错误。



我在各个地方都看到它应该是 Mul softmax 分别为初始v3,但这些值对我不起作用。



我的问题是:什么是图层(问候到这个上下文),我怎么知道我的是什么?





找到您感兴趣的节点并选择它以查找其名称(在左上角的信息中) (b)输入:

输出:



请注意,通常您不需要节点名称,也不需要张量名称。在大多数情况下,只需将:0 添加到节点名称即可获得张量名称。



例如运行上面使用图表中的名称创建的初始v3网络使用以下代码(上述代码的延续):



  import numpy as np 

data = np.random.randn(1,224,224,3)#just random data
session = tf .InteractiveSession()
session.run(tf.global_variables_initializer())
result = session.run('InceptionV3 / Predictions / Softmax:0',feed_dict = {'占位符:0':数据})
#result.shape =(1,1000)


I'm very new to Tensorflow, and I'm trying to train something using the inception v3 network for use in an iPhone app. I managed to export my graph as a protocolbuffer file, manually remove the dropout nodes (correctly, I hope), and have placed that .pb file in my iOS project, but now I am receiving the following error:

Running model failed:Not found: FeedInputs: unable to find feed output input

which seems to indicate that my input_layer_name and output_layer_name variables in the iOS app are misconfigured.

I see in various places that it should be Mul and softmax respectively, for inception v3, but these values don't work for me.

My question is: what is a layer (with regards to this context), and how do I find out what mine are?

This is the exact definition of the model that I trained, but I don't see "Mul" or "softmax" present.

This is what I've been able to learn about layers, but it seems to be a different concept, since "Mul" isn't present in that list.

I'm worried that this might be a duplicate of this question but "layers" aren't explained (are they tensors?) and graph.get_operations() seems to be deprecated, or maybe I'm using it wrong.

解决方案

As MohamedEzz wrote there are no layers in Tensorflow graphs. There are only operations that can be placed under the same name scope.

Usually operations of a single layer placed under the same scope and applications that aware of name scope concept can display them grouped.

One of such applications is Tensorboard. I believe that using Tensorboard is the easiest way to find node names.

Consider the following example:

import tensorflow as tf
import tensorflow.contrib.slim.nets as nets

input_placeholder = tf.placeholder(tf.float32, shape=(None, 224, 224, 3))

network = nets.inception.inception_v3(input_placeholder)

writer = tf.summary.FileWriter('.', tf.get_default_graph())

writer.close()

It creates placeholder for input data then creates Inception v3 network and saves event data (with graph) in current directory.

Launching Tensorflow in the same directory makes it possible to view graph structure.

tensorboard --logdir .

Tensorboard prints UI url to the console

Starting TensorBoard 41 on port 6006
(You can navigate to http://192.168.128.73:6006)

Below is an image of this graph.

Locate node you are interested in and select it to find its name (in the upper left information pane).

Input: Output:

Please note that usually you need not node names but tensor names. In most cases it is enough to add :0 to node name to get tensor name.

For example to run Inception v3 network created above using names from the graph use the following code (continuation of the above code):

import numpy as np

data = np.random.randn(1, 224, 224, 3) # just random data
session = tf.InteractiveSession()
session.run(tf.global_variables_initializer())
result = session.run('InceptionV3/Predictions/Softmax:0', feed_dict={'Placeholder:0': data})
# result.shape = (1, 1000)

这篇关于如何获取要在iOS示例应用程序中使用的图层名称? (Tensorflow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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