標籤:current 等價 輸出 lstm 資料 mod vol ued 串連
封裝器WrapperTimeDistributed封裝器
keras.layers.wrappers.TimeDistributed(layer)
該封裝器可以把一個層應用到輸入的每一個時間步上
參數
輸入至少為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
,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‘)
艾伯特(http://www.aibbt.com/)國內第一家人工智慧門戶
Keras官方中文文檔:封裝器Wrapper