相关疑难解决方法(0)

时间分布层在Keras中的作用是什么?

我试图了解TimeDistributed wrapper在Keras中的作用.

我得到TimeDistributed"将一个图层应用于输入的每个时间片."

但我做了一些实验并得到了我无法理解的结果.

简而言之,与LSTM层相关,TimeDistributed和Dense层具有相同的结果.

model = Sequential()
model.add(LSTM(5, input_shape = (10, 20), return_sequences = True))
model.add(TimeDistributed(Dense(1)))
print(model.output_shape)

model = Sequential()
model.add(LSTM(5, input_shape = (10, 20), return_sequences = True))
model.add((Dense(1)))
print(model.output_shape)
Run Code Online (Sandbox Code Playgroud)

对于这两种型号,我的输出形状为(无,10,1).

任何人都可以解释RNN层之后TimeDistributed和Dense层之间的区别吗?

python machine-learning neural-network deep-learning keras

51
推荐指数
1
解决办法
2万
查看次数

在Keras中的TimeDistributed(Dense)vs Dense - 相同数量的参数

我正在构建一个模型,使用循环图层(GRU)将字符串转换为另一个字符串.我已经尝试了Dense和TimeDistributed(密集)层作为最后一层,但我不明白使用return_sequences = True时两者之间的区别,特别是因为它们似乎具有相同数量的参数.

我的简化模型如下:

InputSize = 15
MaxLen = 64
HiddenSize = 16

inputs = keras.layers.Input(shape=(MaxLen, InputSize))
x = keras.layers.recurrent.GRU(HiddenSize, return_sequences=True)(inputs)
x = keras.layers.TimeDistributed(keras.layers.Dense(InputSize))(x)
predictions = keras.layers.Activation('softmax')(x)
Run Code Online (Sandbox Code Playgroud)

网络摘要是:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 64, 15)            0         
_________________________________________________________________
gru_1 (GRU)                  (None, 64, 16)            1536      
_________________________________________________________________
time_distributed_1 (TimeDist (None, 64, 15)            255       
_________________________________________________________________
activation_1 (Activation)    (None, 64, 15)            0         
=================================================================
Run Code Online (Sandbox Code Playgroud)

这对我来说很有意义,因为我对TimeDistributed的理解是它在所有时间点都应用相同的层,因此Dense层有16*15 + 15 = 255个参数(权重+偏差).

但是,如果我切换到一个简单的Dense图层:

inputs = keras.layers.Input(shape=(MaxLen, InputSize))
x = keras.layers.recurrent.GRU(HiddenSize, return_sequences=True)(inputs)
x = …
Run Code Online (Sandbox Code Playgroud)

machine-learning neural-network keras recurrent-neural-network keras-layer

22
推荐指数
1
解决办法
5994
查看次数