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

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训练好的模型中获取参数(权重))