包裝器WrapperTimeDistributed包裝器keras.layers.wrappers.TimeDistributed(layer) 該包裝器可以把一個(gè)層應(yīng)用到輸入的每一個(gè)時(shí)間步上 參數(shù)
輸入至少為3D張量,下標(biāo)為1的維度將被認(rèn)為是時(shí)間維 例如,考慮一個(gè)含有32個(gè)樣本的batch,每個(gè)樣本都是10個(gè)向量組成的序列,每個(gè)向量長(zhǎng)為16,則其輸入維度為 我們可以使用包裝器 # 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) 程序的輸出數(shù)據(jù)shape為 使用 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包裝器 參數(shù)
例子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') |
|