美文网首页
从Tensorflow训练好的模型中获取参数(权重)

从Tensorflow训练好的模型中获取参数(权重)

作者: 马尔克ov | 来源:发表于2019-07-09 10:24 被阅读0次
import os
import numpy as np
import tensorflow as tf
from tensorflow import saved_model as sm

with tf.Session() as sess:
    path = './serving_models/DeepFMPos/1'
    sm.loader.load(sess, tags=[sm.tag_constants.SERVING], export_dir=path)
    ret =  [v for v in tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES) if v.name.endswith('pos_W:0')]
    print(ret)
    W = sess.run('DeepFMPos/deep_fm/pos_W:0')
    for i in range(0, 100):
        print('pos:{},weight:{}'.format(i,W[i]))

相关文章

网友评论

      本文标题:从Tensorflow训练好的模型中获取参数(权重)

      本文链接:https://www.haomeiwen.com/subject/rrbtkctx.html