2

鉴于下面的代码

encoder_inputs = Input(shape=(16, 70))
encoder = LSTM(latent_dim, return_state=True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
# We discard `encoder_outputs` and only keep the states.
encoder_states = [state_h, state_c]

# Set up the decoder, using `encoder_states` as initial state.
decoder_inputs = Input(shape=(59, 93))
# We set up our decoder to return full output sequences,
# and to return internal states as well. We don't use the
# return states in the training model, but we will use them in inference.
decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True)
decoder_outputs,_,_ = decoder_lstm(decoder_inputs,
                                     initial_state=encoder_states)
decoder_dense = TimeDistributed(Dense(93, activation='softmax'))
decoder_outputs = decoder_dense(decoder_outputs)

# Define the model that will turn
# `encoder_input_data` & `decoder_input_data` into `decoder_target_data`
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)

如果我改变

decoder_dense = TimeDistributed(Dense(93, activation='softmax'))

decoder_dense = Dense(93, activation='softmax')

它仍然有效,但哪种方法更有效?

4

1 回答 1

3

如果您的数据依赖于时间,例如Time Series数据或包含不同帧的数据Video,那么时间Distributed Dense层比简单Dense层有效。

Time Distributed Dense在单元展开dense期间对每个时间步应用相同的层。GRU/LSTM这就是为什么误差函数会在predicted label sequence和之间的原因actual label sequence

使用return_sequences=FalseDense图层将仅在最后一个单元格中应用一次。这通常RNNs是用于分类问题的情况。

如果return_sequences=True,则该Dense层用于在每个时间步应用,就像TimeDistributedDense.

在您的模型中,两者都是相同的,但是如果您将第二个模型更改为return_sequences=False,则Dense将仅应用于最后一个单元格。

希望这可以帮助。快乐学习!

于 2020-05-22T11:18:17.757 回答