• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > tensorflow ckpt模型和pb模型获取节点名称,及ckpt转pb模型实例

tensorflow ckpt模型和pb模型获取节点名称,及ckpt转pb模型实例

作者:三寸光阴___ 字体:[增加 减小] 来源:互联网

三寸光阴___ 通过本文主要向大家介绍了tensorflow,节点名称,ckpt,pb等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

ckpt

from tensorflow.python import pywrap_tensorflow 
checkpoint_path = 'model.ckpt-8000' 
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path) 
var_to_shape_map = reader.get_variable_to_shape_map() 
for key in var_to_shape_map: 
 print("tensor_name: ", key)

pb

import tensorflow as tf
import os

model_name = './mobilenet_v2_140_inf_graph.pb'

def create_graph():
 with tf.gfile.FastGFile(model_name, 'rb') as f:
  graph_def = tf.GraphDef()
  graph_def.ParseFromString(f.read())
  tf.import_graph_def(graph_def, name='')

create_graph()
tensor_name_list = [tensor.name for tensor in tf.get_default_graph().as_graph_def().node]
for tensor_name in tensor_name_list:
 print(tensor_name,'\n')

ckpt转pb

def freeze_graph(input_checkpoint,output_graph):
 '''
 :param input_checkpoint:
 :param output_graph: PB模型保存路径
 :return:
 '''
 output_node_names = "xxx"
 saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=True)
 graph = tf.get_default_graph()
 input_graph_def = graph.as_graph_def()
 with tf.Session() as sess:
  saver.restore(sess, input_checkpoint)
  output_graph_def = graph_util.convert_variables_to_constants( 
   sess=sess,
   input_graph_def=input_graph_def,# 等于:sess.graph_def
   output_node_names=output_node_names.split(","))
  with tf.gfile.GFile(output_graph, "wb") as f:
   f.write(output_graph_def.SerializeToString()) 
  print("%d ops in the final graph." % len(output_graph_def.node)) 
 
  for op in graph.get_operations():
   print(op.name, op.values())

以上这篇tensorflow ckpt模型和pb模型获取节点名称,及ckpt转pb模型实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能想查找下面的文章:

  • tensorflow模型保存、加载之变量重命名实例
  • tensorflow模型保存、加载之变量重命名实例
  • 使用tensorflow DataSet实现高效加载变长文本输入
  • TensorFlow——Checkpoint为模型添加检查点的实例
  • TensorFlow实现打印每一层的输出
  • tensorflow ckpt模型和pb模型获取节点名称,及ckpt转pb模型实例
  • tensorflow estimator 使用hook实现finetune方式
  • tensorflow查看ckpt各节点名称实例
  • 浅谈tensorflow中Dataset图片的批量读取及维度的操作详解
  • 浅谈Tensorflow 动态双向RNN的输出问题

相关文章

  • python计算最小优先级队列代码分享
  • Python在Windows和在Linux下调用动态链接库的教程
  • Python 代码性能优化技巧分享
  • 在Python中marshal对象序列化的相关知识
  • 在Python的Django框架的视图中使用Session的方法
  • 简单掌握Python的Collections模块中counter结构的用法
  • 使用Node.js和Socket.IO扩展Django的实时处理功能
  • 在Python中操作字典之clear()方法的使用
  • python实现同时给多个变量赋值的方法
  • Python中多线程thread与threading的实现方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 简单介绍Python的轻便web框架Bottle
    • python中readline判断文件读取结束的方法
    • Python切片用法实例教程
    • python模拟新浪微博登陆功能(新浪微博爬虫)
    • Python中使用platform模块获取系统信息的用法教程
    • Python中的字符串查找操作方法总结
    • Python标准库之collections包的使用教程
    • 用Python脚本来删除指定容量以上的文件的教程
    • Python常用随机数与随机字符串方法实例
    • python访问mysql数据库的实现方法(2则示例)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有