tensorflow学习笔记

2017-10-24  本文已影响10人  钢铁油腻男

老旧tensorflow的api对比

tf.nn.seq2seq.sequence_loss_by_example -> tf.contrib.legacy_seq2seq.sequence_loss_by_example
tf.nn.rnn_cell -> tf.contrib.rnn

tensorflow.Variable与 get_variable的区别

简而言之, get_variable用户共享的变量, 所以使用了两次一模一样的参数的时候, 就会提示错误;
而 tf.variable_scope("scope1", reuse=True)后, 下面再次出现一模一样的参数, 就会去那个共享的variable。

import tensorflow as tf

with tf.variable_scope("scope1"):
    w1 = tf.get_variable("w1", shape=[])
    w2 = tf.Variable(0.0, name="w2")
with tf.variable_scope("scope1", reuse=True):
    w1_p = tf.get_variable("w1", shape=[])
    w2_p = tf.Variable(1.0, name="w2")

print(w1 is w1_p, w2 is w2_p)
#输出
#True  False
上一篇下一篇

猜你喜欢

热点阅读