Tensorflow读取并输出已保存模型的权重数值方式
作者:AManFromEarth 时间:2023-09-15 10:07:49
这篇文章是为了对网络模型的权重输出,可以用来转换成其他框架的模型。
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow
#首先,使用tensorflow自带的python打包库读取模型
model_reader = pywrap_tensorflow.NewCheckpointReader(r"model.ckpt")
#然后,使reader变换成类似于dict形式的数据
var_dict = model_reader.get_variable_to_shape_map()
#最后,循环打印输出
for key in var_dict:
print("variable name: ", key)
print(model_reader.get_tensor(key))
结果(其中一个权重的示例)
........
variable name: InceptionV3/Mixed_7c/Branch_3/Conv2d_0b_1x1/weights
[[[[ 0.00013783 -0.00251428 0.02235526 ... -0.01409702 0.00340105
-0.00752808]
[ 0.01590012 -0.00258413 -0.00627338 ... -0.03600493 0.01220086
-0.01254225]
[-0.02394262 -0.00764508 -0.00895328 ... -0.01731405 0.03568469
0.00918952]
...
[-0.01865693 -0.00358359 -0.02342288 ... 0.00935838 0.00367858
-0.00976252]
[ 0.01297642 0.00223457 0.00652326 ... -0.00762609 -0.0136022
-0.01129473]
[-0.01395879 -0.00920246 0.01061887 ... 0.0236958 0.00041993
-0.01291134]]]]
......
来源:https://blog.csdn.net/AManFromEarth/article/details/81057577
标签:Tensorflow,输出,模型,权重数值
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Vue实现自定义字段导出EXCEL的示例代码
2024-04-27 16:12:09
![](https://img.aspxhome.com/file/2023/2/132962_0s.png)
Python基于numpy灵活定义神经网络结构的方法
2023-09-30 15:03:52
从XML中读取数据到内存的实例
2008-09-04 14:43:00
详解ABP框架中的数据过滤器与数据传输对象的使用
2024-05-02 17:19:47
vscode配置anaconda3的方法步骤
2023-11-05 16:45:02
![](https://img.aspxhome.com/file/2023/3/114613_0s.png)
python GUI库图形界面开发之PyQt5信号与槽事件处理机制详细介绍与实例解析
2021-03-23 03:49:14
![](https://img.aspxhome.com/file/2023/4/85054_0s.png)
如何用 Python 制作 GitHub 消息助手
2021-05-15 03:54:44
![](https://img.aspxhome.com/file/2023/8/133198_0s.png)
tensorflow 实现从checkpoint中获取graph信息
2023-01-05 09:38:41
tensorflow2.0如何实现cnn的图像识别
2022-05-01 21:19:58
![](https://img.aspxhome.com/file/2023/9/77809_0s.jpg)
贝聿铭写给年轻设计师的十点忠告
2010-01-24 18:46:00
![](/images/sg_trans.gif)
python3爬虫中多线程的优势总结
2023-05-15 02:41:07
asp查询xml的代码 不刷新页面查询的方法
2011-04-06 11:00:00
python画折线图的程序
2021-07-04 18:08:20
![](https://img.aspxhome.com/file/2023/5/131115_0s.jpg)
利用Python破解生日悖论问题
2022-11-08 02:37:55
![](https://img.aspxhome.com/file/2023/5/67365_0s.jpg)
MySQL优化教程之慢查询日志实践
2024-01-24 11:22:57
![](https://img.aspxhome.com/file/2023/7/124817_0s.png)
日常收集整理php正则表达式(超常用)
2024-05-03 15:35:49
JavaScript版俄罗斯方块Easy Tetris实现原理
2009-07-16 10:25:00
![](https://img.aspxhome.com/file/UploadPic/20097/16/i2009621214419-26s.jpg)
MySql存储过程循环的使用分析详解
2024-01-19 05:13:48
![](https://img.aspxhome.com/file/2023/9/112669_0s.png)
Mysql 1864 主从错误解决方法
2024-01-17 05:01:35
![](https://img.aspxhome.com/file/2023/7/127567_0s.png)
详解Golang 与python中的字符串反转
2021-08-01 23:31:08