查看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);

最新文章

  1. lucene 索引 demo
  2. Html5新标签解释及用法
  3. php关于static关键字
  4. Nginx工作原理和优化、漏洞
  5. Nginx下Redmine2.6配置
  6. How to manage and balance “Huge Data Load” for Big Kafka Clusters---reference
  7. IE8下ckeditor无法正常使用,提示"例外被抛出且未被接住"的解决办法
  8. vim乱码问题
  9. 抽象类 abstract 和 接口 interface 类的区别
  10. MERGE语法详解
  11. 在用jQuery时遇到的小问题
  12. 面试必问---HashMap原理分析
  13. 剑指offer-面试题7:俩个栈实现队列(java)
  14. PowerDesigner 提示 Existence of index、key、reference错误
  15. @Autowired 基本介绍,有待丰富
  16. MapReduce实例学习
  17. mysql主从配置,读写分离
  18. 5. 多重背包问题 II 【用二进制优化】
  19. MFQ
  20. 超简单,centos7安装docker

热门文章

  1. [转]STL之vector容器详解
  2. CSS——行业动态demo
  3. servlet-响应信息
  4. Requests库 更新中
  5. 前端领域的BEM到底是什么
  6. SQL With As 用法Sql 四大排名函数(ROW_NUMBER、RANK、DENSE_RANK、NTILE)简介
  7. HDU 3152 Obstacle Course(优先队列,广搜)
  8. UID中RUID、EUID和SUID的区别
  9. pandas - 案例(美国各州人口普查)
  10. 第八节:pandas字符串