代码拉取完成,页面将自动刷新
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}.")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。