1 Star 0 Fork 0

Mr_Mao/pytorch-ssd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
extract_tf_weights.py 967 Bytes
一键复制 编辑 原始数据 按行查看 历史
Hao 提交于 2018-06-18 13:58 . add a tool to extract weights from tf models
import tensorflow as tf
from tensorflow.python.platform import gfile
from tensorflow.python.framework import tensor_util
import sys
import pickle
def read_weights(frozen_model):
weights = {}
with tf.Session() as sess:
with gfile.FastGFile(frozen_model, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def)
for n in graph_def.node:
if n.op == 'Const':
weights[n.name] = tensor_util.MakeNdarray(n.attr['value'].tensor)
print("Name:", n.name, "Shape:", weights[n.name].shape)
return weights
if len(sys.argv) < 3:
print("Usage: python extract_tf_weights.py <frozen_model.pb> <weights_file.pickle>")
frozen_model = sys.argv[1]
weights_file = sys.argv[2]
weights = read_weights(frozen_model)
with open(weights_file, "wb") as f:
pickle.dump(weights, f)
print(f"Saved weights to {weights_file}.")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/passer_x/pytorch-ssd.git
git@gitee.com:passer_x/pytorch-ssd.git
passer_x
pytorch-ssd
pytorch-ssd
master

搜索帮助