微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Tensorflow 1.14.0 中打印冻结推理模型的节点名称?

如何解决如何在 Tensorflow 1.14.0 中打印冻结推理模型的节点名称?

我是 Tensorflow 的新手,目前正在研究将在 Tensorflow 中运行的 YOlov4 对象检测器。我从暗网 yolo 权重创建了一个冻结推理模型 .pb。现在我需要了解转换后的冻结模型输出节点的名称。我正在使用附加脚本将冻结图加载到会话中,并使用最后两行来获取打印模型节点名称。但是,当我执行操作时,我得到一个空列表,这不应该是这种情况。你能帮我打这个野兽吗?请找到重现以下情况所需的代码

import tensorflow as tf
import numpy as np
import sys

from tensorflow.python.ops.gen_array_ops import shape

def load_graph(frozen_graph_filename):
    # We load the protobuf file from the disk and parse it to retrieve the 
    # unserialized graph_def
    with tf.compat.v1.gfile.GFile(frozen_graph_filename,"rb") as f:
        graph_def = tf.compat.v1.GraphDef()
        graph_def.ParseFromString(f.read())

    # Then,we import the graph_def into a new Graph and return it 
    with tf.compat.v1.Graph().as_default() as graph:
        # The name var will prefix every op/nodes in your graph
        # Since we load everything in a new graph,this is not needed
        tf.compat.v1.import_graph_def(graph_def,name="prefix")
    return graph

load_graph('./model.pb')

node_names = [n.name for n in tf.compat.v1.get_default_graph().as_graph_def().node]
print(node_names)

最后,在此链接中找到 tensorflow 冻结模型:https://drive.google.com/file/d/1MOa7MLMX6wvKvnV-43F5ZBOxMW8OeCMs/view?usp=sharing

我想请求您的仁慈,因为这是我在 Stack Overflow 上的第一篇文章,如果我的问题不完整,我深表歉意。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。