2017-10-05 104 views
1

我想建立一個Keras層,其中每個節點只需計算上一層中對應節點的對數。我從Keras文檔中看到它的後端模塊中有一個「日誌」功能。但不知何故,我不知道如何使用它。計算對數的keras層?

在此先感謝您提供的任何提示!

回答

0

你可以使用任何後端功能的Lambda層內:

from keras.layers import Lambda 
import keras.backend as K 

定義只是任何函數取輸入張量:

def logFunc(x): 
    return K.log(x) 

,並創建一個lambda層:

#add to the model the way you're used to: 
model.add(Lambda(logFunc,output_shape=(necessaryWithTheano))) 
+0

謝謝!我一直在使用Keras Sequential API構建我的網絡,而不是功能性API。我將如何處理您使用Sequential API的建議? – LWixson

+0

'model.add(Lambda(.....))' –