如何获得Keras模型中的tensorflow输出节点的名称? [英] How do you get the name of the tensorflow output nodes in a Keras Model?

查看:1231
本文介绍了如何获得Keras模型中的tensorflow输出节点的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Keras(tensorflow后端)模型创建一个pb文件,以便可以在iOS上构建它.我正在使用freeze.py,我需要传递输出节点.如何获得Keras模型的输出节点的名称?

I'm trying to create a pb file from my Keras (tensorflow backend) model so I can build it on iOS. I'm using freeze.py and I need to pass the output nodes. How do i get the names of the output nodes of my Keras model?

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py

推荐答案

您可以使用Keras model.summary()来获取最后一层的名称.

You can use Keras model.summary() to get the name of the last layer.

如果model.outputs不为空,则可以通过以下方式获取节点名称:

If model.outputs is not empty you can get the node names via:

[node.op.name for node in model.outputs]

您通过以下方式获得会话

you get the session via

session = keras.backend.get_session()

,然后通过

min_graph = convert_variables_to_constants(session, session.graph_def, [node.op.name for node in model.outputs])

之后,您可以通过

tensorflow.train.write_graph(min_graph, "/logdir/", "file.pb", as_text=True)

这篇关于如何获得Keras模型中的tensorflow输出节点的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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