查看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. 实现PC延迟执行函数

    头文件内容: #pragma once typedef function<void ()> DelayClickHandler; typedef void (*pDelayFun)(); ...

  2. 如何用java生成随机验证码

     1.VerifyCode 类:   1 package com.HRuinger.enity;                          ImageIO.write(image, " ...

  3. 一款批量linux管理工具batchshell

    BatchShell是什么? BatchShell是一款基于SSH2的批量文件传输及命令执行工具,它可以同时传输文件到多台远程服务器以及同时对多台远程服务器执行命令.BatchShell基于原生的sh ...

  4. Find the build UUID in a Crash Report

    1) Find the build UUID in a Crash Report The first line in the "Binary Images:" section of ...

  5. mstsc windows7/10远程桌面身份验证错误 要求的函数不受支持

    之前好好的能远程桌面连接到服务器,但是今天来就不能连接上了,并提示:身份验证错误.要求的函数不受支持. 猜想可能是Windows又更新了什么鬼,后面查询资料知道是由于CredSSP加密Oracle修正 ...

  6. 一、Scrapy入门教程

    本文转载自以下链接:https://scrapy-chs.readthedocs.io/zh_CN/latest/intro/tutorial.html 在本篇教程中,我们假定您已经安装好Scrapy ...

  7. 24.通过ngram分词机制实现index-time搜索推荐

    一.ngram和index-time搜索推荐原理     1.什么是ngram     假设有一个单词:quick,在5种长度下的ngram情况如下: ngram length=1,q u i c k ...

  8. Flask - app的配置和实例化Flask的参数

    目录 Flask - app的配置和实例化Flask的参数 app的配置 app的配置 Flask - app的配置和实例化Flask的参数 app的配置 基本用法: from flask impor ...

  9. hdu 3572 最大流判断满流

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  10. zoj 3693

    #include<stdio.h> #include<string.h>//进位问题如3.985    应该进位3.99 int main() {     int n,k,i; ...