KERAS:获取 return_sequence = True 的 RNN 时间步长 SLICE
KERAS: Get a SLICE of RNN timesteps with return_sequence = True
我的问题很简单,但似乎没有解决。
输入: (bs, timesteps, input_dim) --> Tensor("stack:0", shape=(?, 4 , 400), dtype=float32)
图层:
output = LSTM(100, input_shape = (timesteps, input_feature), return_sequence = True) (input)
预期: (bs, timesteps, output_dim) --> Tensor("gru_20/transpose_1:0", shape=(?, 4 , 100), dtype=float32)
输出: 张量("gru_20/transpose_1:0", shape=(?, ?, 100), dtype=float32)
为什么 Keras 不推断时间步数,即使它收到 input_shape?当我使用模型摘要时,它显示的结果具有正确的输出形状:
lstm_2 (LSTM) (None, 4, 100) 3232
但不是在施工期间。因此,当我想通过使用 unstack(output, axis=1)] 将张量拆分为每个时间步长的张量列表时 * (bs, 10)] 我收到此错误:ValueError: Cannot infer num from shape (?, , 100)
我的错误在哪里?
顺便说一句。添加 TimeDistributed(Dense(100))(questions) 会导致正确的输出暗淡:Tensor("time_distributed_17/Reshape_1:0", shape=(?, 4, 100), dtype=float32)但由于共享权重而不是一种选择。如果没有,解决方法是什么?
变通方法可能是乘以 1(不变)。
workaround = TimeDistributed(Lambda(lambda x: x * 1.0))(output)
推理在这里起作用:
Tensor("time_distributed_17/Reshape_1:0", shape=(?, 4, 100), dtype=float32)
使用 return_sequences=True
时是否总是需要 TimeDistributed
层?
我的问题很简单,但似乎没有解决。
输入: (bs, timesteps, input_dim) --> Tensor("stack:0", shape=(?, 4 , 400), dtype=float32)
图层: output = LSTM(100, input_shape = (timesteps, input_feature), return_sequence = True) (input)
预期: (bs, timesteps, output_dim) --> Tensor("gru_20/transpose_1:0", shape=(?, 4 , 100), dtype=float32)
输出: 张量("gru_20/transpose_1:0", shape=(?, ?, 100), dtype=float32)
为什么 Keras 不推断时间步数,即使它收到 input_shape?当我使用模型摘要时,它显示的结果具有正确的输出形状:
lstm_2 (LSTM) (None, 4, 100) 3232
但不是在施工期间。因此,当我想通过使用 unstack(output, axis=1)] 将张量拆分为每个时间步长的张量列表时 * (bs, 10)] 我收到此错误:ValueError: Cannot infer num from shape (?, , 100)
我的错误在哪里?
顺便说一句。添加 TimeDistributed(Dense(100))(questions) 会导致正确的输出暗淡:Tensor("time_distributed_17/Reshape_1:0", shape=(?, 4, 100), dtype=float32)但由于共享权重而不是一种选择。如果没有,解决方法是什么?
变通方法可能是乘以 1(不变)。
workaround = TimeDistributed(Lambda(lambda x: x * 1.0))(output)
推理在这里起作用:
Tensor("time_distributed_17/Reshape_1:0", shape=(?, 4, 100), dtype=float32)
使用 return_sequences=True
时是否总是需要 TimeDistributed
层?