zoukankan      html  css  js  c++  java
  • 【483】Keras 中 LSTM 与 BiLSTM 语法

    参考:Keras-递归层Recurrent官方说明

    参考:Keras-Bidirectional包装器官方说明

    LSTM(units=32, input_shape=(10, 64))

    • units=32:输出神经元个数
    • input_shape=(10, 64):输入数据形状,10 代表时间序列的长度,64 代表每个时间序列数据的维度

    LSTM(units=32, input_dim=64, input_length=10)

    • units=32:输出神经元个数
    • input_dim=64:每个时间序列数据的维度
    • input_length=10:时间序列的长度

    ☀☀☀<< 举例 >>☀☀☀

    # as the first layer in a Sequential model
    model = Sequential()
    model.add(LSTM(32, input_shape=(10, 64)))
    # now model.output_shape == (None, 10, 32)
    # note: `None` is the batch dimension.
    
    # the following is identical:
    model = Sequential()
    model.add(LSTM(32, input_dim=64, input_length=10))
    
    # for subsequent layers, not need to specify the input size:
    model.add(LSTM(16))
    

      

    • return_sequences:布尔值,默认False,控制返回类型。若为True则返回整个序列,否则仅返回输出序列的最后一个输出

    keras.layers.wrappers.Bidirectional(layer, merge_mode='concat', weights=None)

      双向RNN包装器 

      参数

    • layer:Recurrent对象
    • merge_mode:前向和后向RNN输出的结合方式,为sum,mul,concat,ave和None之一,若设为None,则返回值不结合,而是以列表的形式返回

    ☀☀☀<< 举例 >>☀☀☀

    model = Sequential()
    model.add(Bidirectional(LSTM(10, return_sequences=True), input_shape=(5, 10)))
    model.add(Bidirectional(LSTM(10)))
    model.add(Dense(5))
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
    

      

  • 相关阅读:
    iBatis系列一
    iBatis入手案例
    需求分析7字诀
    自我意识为王
    物联网关键技术之一
    物联网之二:传感器无线网络
    物联网之二:传感器无线网络
    物联网时代之一
    项目经理的心法
    项目管理规划
  • 原文地址:https://www.cnblogs.com/alex-bn-lee/p/13727451.html
Copyright © 2011-2022 走看看