Keras: Lambda layer function with multiple parameters

僤鯓⒐⒋嵵緔 提交于 2019-12-05 17:42:56

问题


I am trying to write a Lambda layer in Keras which calls a function connection, that runs a loop for i in range(0,k) where k is fed in as an input to the function, connection(x,k). Now, when I try to call the function in the Functional API, I tried using:

k = 5
y = Lambda(connection)(x)

Also,

y = Lambda(connection)(x,k)

But neither of those approaches worked. How can I feed in the value of k without assigning it as a global parameter?


回答1:


Just use

y = Lambda(connection)((x,k)) 

and then var[0], var[1] in connection method




回答2:


Found the solution to the problem in this GitHub Pull Request. Using

y = Lambda(connection, arguments={'k':k})(x)

worked!



来源:https://stackoverflow.com/questions/44931347/keras-lambda-layer-function-with-multiple-parameters

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