2017-03-16 225 views
2

假設我有10萬的數據集400 X我建立這個模型:Keras,如何得到預測與模型去掉最後一層

model = Sequential() 
model.add(Dense(200, input_dim = 400, init = init_weights)) 
model.add(BatchNormalization()) 
model.add(SReLU()) 
model.add(Dropout(0.5)) 
model.add(Dense(200, init = init_weights)) 
model.add(BatchNormalization()) 
model.add(SReLU()) 
model.add(Dropout(0.5)) 
model.add(Dense(1, activation = 'linear', init = init_weights)) 

比我打電話

model.compile(loss = .. 

而且

model.fit(input_matrix,.. 

訓練結束後,我可以調用model.predict(..用於預測。

我想獲得從去年沒有線性分層模型預測矩陣..

因此,像:

model.remove_last_layer 
pred_matrix = model.predict(input_matrix) 

其產量100K×200陣列,我怎麼能做到這一點與keras? THX很多

+0

你有你的模型中訓練的? –

+0

是的,我得到了訓練 – gugatr0n1c

+0

什麼是你的'後端',你能打印'model.summary()'? –

回答

1

THX以鏈接的文檔,我發現這個

layer_name = 'dropout_2' 
intermediate_layer_model = Model(input = model.input, output = model.get_layer(layer_name).output) 
intermediate_output = intermediate_layer_model.predict(matrix_test) 
+0

Againts官方文檔我更改爲keras_1 API – gugatr0n1c