Keras return_state和return_sequences

1.常见的4中结构

Keras return_state和return_sequences_第1张图片

  • one to one:
    • model.add(Dense(output_size, input_shape=input_shape))
  • one to many:
    • model.add(RepeatVector(number_of_times, input_shape=input_shape))
      model.add(LSTM(output_size, return_sequences=True))
  • many to one:
    • model = Sequential()
      model.add(LSTM(1, input_shape=(timesteps, data_dim)))
  • many to many:
    • model = Sequential()
      model.add(LSTM(1, input_shape=(timesteps, data_dim), return_sequences=True))

ref:https://stackoverflow.com/questions/43034960/many-to-one-and-many-to-many-lstm-examples-in-keras

2.return_sequences 和 return_state

return_sequences:

Keras return_state和return_sequences_第2张图片

  • 每一步都有隐藏状态 a,不同结构计算方式不同
  • 默认FALSE,为TRUE时可以达到 *-to-many的效果

return_state:

Keras return_state和return_sequences_第3张图片

  • state指的是cell里的 c
  • 默认FALSE,为TRUE时可以输出最后一个state
  • ref有详述:https://www.dlology.com/blog/how-to-use-return_state-or-return_sequences-in-keras/

你可能感兴趣的:(Keras return_state和return_sequences)