预训练张量流神经网络模型

时间:2018-09-19 20:50:34

标签: tensorflow neural-network deep-learning

如何从预训练的张量流中获取提取权重?我是第一次使用tensorflow。

1 个答案:

答案 0 :(得分:1)

假设您已经训练了模型或恢复了先前训练的模型,则可以使用与图形对象关联的get_tensor_by_name()方法获得任何张量。

weights = graph.get_tensor_by_name("NameScope/name:0")

如果您的权重在图表中定义如下:

with tf.name_scope("Variables"):
    initial = tf.random_normal(dtype=tf.float32, shape=shape)
    l1_weights = tf.Variable(initial, name="weights")

然后可以使用进行培训后访问它们

trained_weights = graph.get_tensor_by_name("Variables/weights:0")

有关保存和恢复训练有素的模型的信息,可以找到here

以及有关get_tensor_by_name()的详细信息可以在here中找到。

相关问题