tensorflow学习笔记

老旧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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容