查看tensorflow pb模型文件的节点信息:

import tensorflow as tf
with tf.Session() as sess:
with open('./quantized_model.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
print graph_def

效果:

# ...
node {
name: "FullyConnected/BiasAdd"
op: "BiasAdd"
input: "FullyConnected/MatMul"
input: "FullyConnected/b/read"
attr {
key: "T"
value {
type: DT_FLOAT
}
}
attr {
key: "data_format"
value {
s: "NHWC"
}
}
}
node {
name: "FullyConnected/Softmax"
op: "Softmax"
input: "FullyConnected/BiasAdd"
attr {
key: "T"
value {
type: DT_FLOAT
}
}
}
library {
}

参考:https://tang.su/2017/01/export-TensorFlow-network/

https://github.com/tensorflow/tensorflow/issues/15689

一些核心代码:

import tensorflow as tf
with tf.Session() as sess:
with open('./graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
print graph_def
output = tf.import_graph_def(graph_def, return_elements=['out:0'])
print(sess.run(output))

This is part of my Tensorflow frozen graph, I have named the input and output nodes.

>>> g.ParseFromString(open('frozen_graph.pb','rb').read())
>>> g
node {
name: "input"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
key: "shape"
value {
shape {
dim {
size: -1
}
dim {
size: 68
}
}
}
}
}
...
node {
name: "output"
op: "Softmax"
input: "add"
attr {
key: "T"
value {
type: DT_FLOAT
}
}
}

I ran this model by the following code
(CELL is name of directory where my file is located)

final String MODEL_FILE = "file:///android_asset/" + CELL + "/optimized_graph.pb" ;
final String INPUT_NODE = "input" ;
final String OUTPUT_NODE = "output" ;
final int[] INPUT_SIZE = {1,68} ;
float[] RESULT = new float[8]; inferenceInterface = new TensorFlowInferenceInterface();
inferenceInterface.initializeTensorFlow(getAssets(),MODEL_FILE) ;
inferenceInterface.fillNodeFloat(INPUT_NODE,INPUT_SIZE,input);

and finally

inferenceInterface.readNodeFloat(OUTPUT_NODE,RESULT);

查看tensorflow pb模型文件的节点信息的更多相关文章

  1. 查看tensorflow Pb模型所有层的名字

    代码如下: import tensorflow as tf def get_all_layernames(): """get all layers name"& ...

  2. tensorflow c++ API加载.pb模型文件并预测图片

    tensorflow  python创建模型,训练模型,得到.pb模型文件后,用c++ api进行预测 #include <iostream> #include <map> # ...

  3. h5模型文件转换成pb模型文件

      本文主要记录Keras训练得到的.h5模型文件转换成TensorFlow的.pb文件 #*-coding:utf-8-* """ 将keras的.h5的模型文件,转换 ...

  4. MxNet 模型转Tensorflow pb模型

    用mmdnn实现模型转换 参考链接:https://www.twblogs.net/a/5ca4cadbbd9eee5b1a0713af 安装mmdnn pip install mmdnn 准备好mx ...

  5. 134、TensorFlow检查点checkpoint文件中的信息

    # 1.你想创建多少Saver对象就可以创建多少,如果你需要去保存和恢复不同的子图模型 # 同样的变量可以在不同的saver对象中被加载 # 只有在Saver.restore()方法被调用的时候才会对 ...

  6. tensorflow学习笔记——模型持久化的原理,将CKPT转为pb文件,使用pb模型预测

    由题目就可以看出,本节内容分为三部分,第一部分就是如何将训练好的模型持久化,并学习模型持久化的原理,第二部分就是如何将CKPT转化为pb文件,第三部分就是如何使用pb模型进行预测. 一,模型持久化 为 ...

  7. C#中如何创建xml文件 增、删、改、查 xml节点信息

    XML:Extensible Markup Language(可扩展标记语言)的缩写,是用来定义其它语言的一种元语言,其前身是SGML(Standard Generalized Markup Lang ...

  8. tensorflow的ckpt文件总结

    1.TensorFlow的模型文件 --checkpoint_dir | |--checkpoint | |--MyModel.meta | |--MyModel.data-00000-of-0000 ...

  9. delphi 文件操作(信息获取)

    delphi获取Exe文件版本信息的函数 Type TFileVersionInfo = Record FixedInfo:TVSFixedFileInfo; {版本信息} CompanyName:S ...

随机推荐

  1. H5 标签属性、input属性

    高亮文字: 全部商品只要<mark>6.18</mark> 结果:     加拼音文字: <ruby>變<rt>bian</rt></ ...

  2. JS——旋转木马

    1.opacity和zIndex的综合运用 2.样式的数组的替换:向右边滑动---删除样式数组第一位并在数组最后添加:向左边滑动---删除样式数组最后一位并在数组前添加 3.开闭原则,只有当回调函数执 ...

  3. 开源业务规则引擎JBoss Drools

    Drools 是什么? 规则引擎由推理引擎发展而来,是一种嵌入在应用程序中的组件,实现了将业务决策从应用程序代码中分离出来,并使用预定义的语义模块编写业务决策.接受数据输入,解释业务规则,并根据业务规 ...

  4. java攻城师之路--复习java web之servlet

    需要掌握的知识点:1.Servlet程序编写 ----- 生命周期2.ServletAPI Request Response 3.Cookie 和 Session Servlet 用来 动态web资源 ...

  5. [Windows Server 2008] 查看ASP.net详细错误信息

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:查看IIS ...

  6. 5.C#编写Redis访问类

    那么通过前面几篇博文,服务端的安装和配置应该没什么问题了,接下来的问题是如何通过代码来访问Redis. 这里我们使用的库为: StackExchange.Redis GitHub:https://gi ...

  7. HDU_1028_Ignatius and the Princess III_(母函数,dp)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. 关于 实体类中 时间字段 为string 类型和 datatime类型 比较

    经发现, 数据库中保存时间格式数据  可以正常 排序, 数据中保存时间格式字符串 排序出现问题 /// <summary> /// 修改时间 /// </summary> pu ...

  9. C# 统计字符串出现的个数

    string str1 = "123AAA456AAAA789AAAAAAA1011"; string str2 = "123456789AAA23456789AAAA3 ...

  10. for mxl path

    废话不多说,直接上例子 简单明了 create table tb_class ( classId int , className ) ) go ,'一班') ,'二班') ,'三班') go crea ...