因为乌鸦像写字台 2019-03-08 16:51 采纳率: 50%
浏览 1333
已结题

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

我看到很多样例代码中, 展开实现LSTM按时间步迭代时,都如下加上了一句
if timestep > 0:
tf.get_variable_scope().reuse_variables()

with tf.variable_scope('RNN'):
    for timestep in range(timestep_size):
        if timestep > 0:
            tf.get_variable_scope().reuse_variables()
        # 这里的state保存了每一层 LSTM 的状态
        (cell_output, state) = mlstm_cell(X[:, timestep, :], state)

我查了各类RNNCELL类的源代码,发现除了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
所以我个人认为这句不需要加,求各位帮忙解答下,该不该加这句话

  • 写回答

2条回答

  • threenewbee 2019-03-08 16:52
    关注

    构造CNN以及LSTM等模型的时候,需要重复使用共享权重
    如果你不要重复使用共享权重,就不要这一句

    评论

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面