Keras官方中文文檔:封裝器Wrapper

來源:互聯網
上載者:User

標籤:current   等價   輸出   lstm   資料   mod   vol   ued   串連   

封裝器WrapperTimeDistributed封裝器
keras.layers.wrappers.TimeDistributed(layer)

該封裝器可以把一個層應用到輸入的每一個時間步上

參數
  • layer:Keras層對象

輸入至少為3D張量,下標為1的維度將被認為是時間維

例如,考慮一個含有32個樣本的batch,每個樣本都是10個向量組成的序列,每個向量長為16,則其輸入維度為(32,10,16),其不包含batch大小的input_shape(10,16)

我們可以使用封裝器TimeDistributed封裝Dense,以產生針對各個時間步訊號的獨立全串連:

# as the first layer in a modelmodel = Sequential()model.add(TimeDistributed(Dense(8), input_shape=(10, 16)))# now model.output_shape == (None, 10, 8)# subsequent layers: no need for input_shapemodel.add(TimeDistributed(Dense(32)))# now model.output_shape == (None, 10, 32)

程式的輸出資料shape為(32,10,8)

使用TimeDistributed封裝Dense嚴格等價於layers.TimeDistribuedDense。不同的是封裝器TimeDistribued還可以對別的層進行封裝,如這裡對Convolution2D封裝:

model = Sequential()model.add(TimeDistributed(Convolution2D(64, 3, 3), input_shape=(10, 3, 299, 299)))
Bidirectional封裝器
keras.layers.wrappers.Bidirectional(layer, merge_mode=‘concat‘, weights=None)

雙向RNN封裝器

參數
  • layer:Recurrent對象
  • merge_mode:前向和後向RNN輸出的結合方式,為sum,mul,concat,aveNone之一,若設為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‘)

艾伯特(http://www.aibbt.com/)國內第一家人工智慧門戶

Keras官方中文文檔:封裝器Wrapper

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.