weixin_42511145
因为乌鸦像写字台
2019-04-06 15:23

RNN 展开实现LSTM按时间步迭代时,有必要令reuse=true么?

10
  • tensorflow
  • 深度学习
  • 人工智能
  • 自然语言处理
  • 神经网络

我看到很多样例代码中, 展开实现LSTM按时间步迭代时,都如下加上了一句

if timestep > 0:
    tf.get_variable_scope().reuse_variables()

我查了各类RNN CELL类的源代码,发现除了call函数外,还有build函数(此函数似乎是在创建所有的变量),且此函数只调用一次,并且是在call调用之前调用,并且查看源码注释时发现是这样写的:

    For backwards compatibility purposes, most RNNCell instances allow their call methods to instantiate variables via tf.get_variable. The underlying variable scope thus keeps track of any variables, and returning cached versions. This is atypical of tf.layer objects, which separate this part of layer building into a build method that is only called once.
    Here we provide a subclass for RNNCell objects that act exactly as Layer objects do. They must provide a build method and their call methods do not access Variables tf.get_variable

所以我个人认为这句不需要加,求各位帮忙解答下,该不该加这句话?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐