如何获取在 iOS 示例应用程序中使用的图层名称? (张量流)

2024-03-07

我对 Tensorflow 非常陌生,我正在尝试使用 inception v3 网络来训练一些东西,以便在 iPhone 应用程序中使用。我设法将图表导出为协议缓冲区文件,手动删除 dropout 节点(我希望是正确的),并将该 .pb 文件放入我的 iOS 项目中,但现在我收到以下错误:

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

这似乎表明我的input_layer_name and output_layer_nameiOS 应用程序中的变量配置错误。

我在很多地方看到它应该是Mul and softmax分别适用于 inception v3,但这些值对我不起作用。

我的问题是:什么是层(就这个上下文而言),以及如何找出我的层是什么?

This https://github.com/tensorflow/models/blob/master/inception/inception/slim/inception_model.py是我训练的模型的确切定义,但我没有看到“Mul”或“softmax”存在。

This https://www.tensorflow.org/api_guides/python/contrib.layers是我能够了解的关于层的知识,但这似乎是一个不同的概念,因为“Mul”不存在于该列表中。

我担心这可能是重复的这个问题 https://stackoverflow.com/questions/35740594/layer-names-for-pretrained-inception-v3-model-tensorflow但没有解释“层”(它们是张量吗?)并且graph.get_operations() seems被弃用,或者我可能使用错误。


As 穆罕默德·伊兹 https://stackoverflow.com/a/43436440/3086290写道 Tensorflow 图中没有层。只有可以放置在同名范围下的操作。

通常,单个层的操作位于同一范围内,并且了解名称范围概念的应用程序可以将它们分组显示。

此类应用之一是张量板 https://www.tensorflow.org/get_started/summaries_and_tensorboard。我相信使用 Tensorboard 是查找节点名称的最简单方法。

考虑以下示例:

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

它为输入数据创建占位符,然后创建 Inception v3 网络并将事件数据(带有图形)保存在当前目录中。

在同一目录中启动 Tensorflow 可以查看图形结构。

tensorboard --logdir .

Tensorboard 将 UI url 打印到控制台

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

Below is an image of this graph. enter image description here

找到您感兴趣的节点并选择它以查找其名称(在左上方的信息窗格中)。

Input: enter image description here Output: enter image description here

请注意,通常您不需要节点名称,而是张量名称。大多数情况下添加就足够了:0到节点名称来获取张量名称。

例如,要使用图中的名称运行上面创建的 Inception 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={'Placeholder:0': data})
# result.shape = (1, 1000)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何获取在 iOS 示例应用程序中使用的图层名称? (张量流) 的相关文章

随机推荐