2 回答

TA貢獻1877條經驗 獲得超6個贊
在您的情況下最有效的方法取決于您如何準確設置和訓練 SVM,但使用回調至少有兩個選項:
您可以使用ModelCheckpoint回調來保存您在每個時期訓練的模型的副本,然后加載所有這些模型以獲得 LSTM 層的輸出。
您還可以通過實現Callback基類來創建自己的回調。在回調中,可以訪問模型,您可以使用on_epoch_end它在每個時期結束時提取 LSTM 輸出。
編輯:要方便地訪問倒數第二層,您可以執行以下操作:
# Create the model with the functional API
inp = Input((train_X.shape[1], train_X.shape[2],))
lstm = LSTM(100, return_sequences=False)(inp)
dense = Dense(train_Y.shape[1], activation='softmax')(lstm)
# Create the full model
model = Model(inputs=inp, outputs=dense)
# Create the model for access to the LSTM layer
access = Model(inputs=inp, outputs=lstm)
然后,您可以access在實例化它時傳遞給您的回調。最關鍵的事情,這里要注意的是,model與access共享同樣的LSTM層,它們的權重會發生變化時訓練model。
添加回答
舉報