tensorflow ckpt模型和pb模型获取节点名称,及ckpt转pb模型实例
作者:三寸光阴___ 发布时间:2021-05-23 10:22:53
标签:tensorflow,节点名称,ckpt,pb
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())
来源:https://blog.csdn.net/qq_38109843/article/details/88841306
0
投稿
猜你喜欢
- 以下各种方式仅供参考,本人亲测只有官方提供的方式比较靠谱。1. 使用多个进程启动多个Tornado实例import tornado.http
- 但是如果在utf-8编码下,一个汉字是占3个字符长度的,比如字符串$str=”你好啊!!”; 如果你用strlen函数来判断,长度是11,正
- 在项目中,我们需要运用到很多来自后端返回的数据。有时是上百条,有时甚至上千条。如果加上后端的多表查询或者数据量过大,这就导致在前
- 当我们拿到一个对象的引用时,如何知道这个对象是什么类型、有哪些方法呢?使用type()首先,我们来判断对象类型,使用type()函数:基本类
- 下面就来介绍下SQL Server 2008中使用的端口有哪些:首先,最常用最常见的就是1433端口。这个是数据库引擎的端口,如果我们要远程
- //定义编码header( 'Content-Type:text/html;charset=utf-8 ');//Atomh
- Json To Dictimport jsonjsonData = '{"a":1,"b":
- 目录一,利用 tensorboardX 可视化网络结构二,利用 vistom 可视化三,利用pytorchviz可视化网络结构一,利用 te
- 前言具有名字的插槽slot使用 中的 "name" 属性绑定元素注意:1,如果没有匹配到 则放到匿名的插槽中2,具名插槽
- 一、报错信息:【file】【Default Settint】---Project Interpreter 点击+搜索suds安装模块报错解决
- 这是不久前写的一个分页存储过程,可应用于SQL Server 2005上面: if object_ID('[proc_SelectF
- 前言使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__方法在类的一个对象被建立时,马上
- 这里我们以用户登录鉴权为例 express依赖express-session中间件实现session功能 若我们不加载express-ses
- win7以上需要使用管理员权限操作。# -*- coding: utf-8 -*-import osimport globimport sh
- MYSQLdump参数详解mysqldump备份:mysqldump -u用户名 -p密码 -h主机 数据库 a -w “sql条件” –l
- 本文实例讲述了js实现文本框宽度自适应文本宽度的方法。分享给大家供大家参考。具体如下:一个会随着输入文本框的字符多少而自动增加宽度的JS代码
- 最近服务器很不稳定,于是重装了mysql 和php 服务,但是接着却遇到了很头疼的麻烦。远程连接mysql是总是提示:Lost connec
- 一.图像金字塔图像金字塔是指由一组图像且不同分别率的子图集合,它是图像多尺度表达的一种,以多分辨率来解释图像的结构,主要用于图像的分割或压缩
- 如下所示:In [1]: import pandas as pd ...: df=pd.DataFrame({"a":[
- 下载golint下载golang 的 lint,下载地址:https://github.com/golang/lintmkdir -p $G