1. 程式人生 > >【TensorFlow】從訓練好的模型中獲取引數值

【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")