【TensorFlow】从训练好的模型中获取参数值

checkpoint_file = tf.train.latest_checkpoint(FLAGS.checkpoint_dir)
graph = tf.Graph()
with graph.as_default():
    session_conf = tf.ConfigProto(
      allow_soft_placement=FLAGS.allow_soft_placement,
      log_device_placement=FLAGS.log_device_placement)
    sess = tf.Session(config=session_conf)
    with sess.as_default():
        # Load the saved meta graph and restore variables
        saver = tf.train.import_meta_graph("{}.meta".format(checkpoint_file))
        saver.restore(sess, checkpoint_file)


        # Get the placeholders from the graph by name
        w = graph. get_operation_by_name("word_embedding/W").outputs[0]

        print sess.run(w)



模型中 关于W的定义:

self.W = tf.Variable(10.0, name = "W")

你可能感兴趣的:(tensorflow)