【问题标题】:residual LSTM layers剩余 LSTM 层
【发布时间】:2019-06-09 10:22:33
【问题描述】:

我无法理解 keras 中 LSTM 层中的张量行为。

我已经预处理了看起来像 [样本、时间步长、特征] 的数字数据。所以 10 000 个样本、24 个时间步长和 10 个预测变量。

我想堆叠剩余连接,但我不确定我做得对:

x <- layer_input(shape = c(24,10))

x <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)

现在 x 的形状,也就是张量,是 [?,?,32]。我期待 [?,32,10]。我应该将数据重塑为 [样本、特征、时间步长]?然后我形成 res:

y <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)

res <- layer_add(c(x, y))

现在我不确定这是否正确,或者我是否应该这样做

x <- layer_input(shape = c(24,10))

y <- layer_lstm(x,units=24,activation="tanh",return_sequences=T) # same as time_steps

res <- layer_add(c(x,y)) ## perhaps here data reshaping is neccesary?

非常感谢任何见解。

JJ

【问题讨论】:

    标签: keras lstm deep-residual-networks


    【解决方案1】:

    LSTM 层将返回暗淡为(?,seq_length,out_dims),其中out_dims 在您的情况下是units。所以整体暗淡将是

    x <- layer_input(shape = c(24,10))
    # dims of x (?,24,10)
    x <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)
    # dims of x after lstm_layer (?,24,32)
    
    y <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)
    # dims of y (?,24,32)
    res <- layer_add(c(x, y))
    # dims of res will be (?,24,32), it is addion of output of both lstm_layer.
    

    欲了解更多信息,您可以check-this

    【讨论】:

    • 所以 LSTM 将采用所有 10 个预测变量并组合 24 个序列,其中将包含所有 10 个预测变量的信息?我对你的理解正确吗? @Ankish Bansal
    • 是的,这里的序列可以看作是时间步长,所以每个时间步长需要 10 个预测变量,计算 32 个暗淡的输出并重复 24 个时间步长
    • 我再问一个子问题。所以如果我担心我会丢失更深层的信息,这些信息是“y”和另一个“res”堆叠在一起的,我应该在我们的例子中保存第一个“x”,然后再添加它? @Ankish Bansal
    • 我没听懂,你是说,如果再添​​加一个 res 块呢?
    • 另外,使用residual layer是松散的词,但更多的是堆叠两层。当我们实际使用残差作为层输出的目标时,使用残差。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多