keras layer that computes logarithms?

风流意气都作罢 提交于 2019-12-24 06:48:04

问题


I'd like to set up a Keras layer in which each node simply computes the logarithm of the corresponding node in the preceding layer. I see from the Keras documentation that there is a "log" function in its backend module. But somehow I'm not understanding how to use this.

Thanks in advance for any hints you can offer!


回答1:


You can use any backend function inside a Lambda layer:

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

Define just any function taking the input tensor:

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

And create a lambda layer with it:

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


来源:https://stackoverflow.com/questions/46595242/keras-layer-that-computes-logarithms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!