Keras: Lambda layer function with multiple parameters

Prabaha picture Prabaha · Jul 5, 2017 · Viewed 11.7k times · Source

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?

Answer

Andrey Nikishaev picture Andrey Nikishaev · Jul 9, 2018

Just use

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

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