I just want to implement a custom layer for taking the l2 norm of two vectors (of matching dimensions of course) which were output by 2 different models in keras. I'm using the functional API method of writing keras functions, so I have stuff like:
inp1 = Input(someshape)
X = Conv2D(someargs)(inp1)
...
...
out1 = Dense(128)(X)
inp2 = Input(someshape)
Y = Conv2D(someargs)(inp2)
...
...
out2 = Dense(128)(Y)
Then I want to take the l2 norm of the distance between out1 and out2 and feed it further into another network, so I have a lambda layer like:
l2dist = keras.layers.Lambda(l2dist)(out1,out2)
Where l2dist is the function defined as:
def l2dist(x,y):
return K.sqrt(K.sum((x-y)**2))
But I get an error for the l2dist =... line saying:
TypeError: __call__() takes 2 positional arguments but 3 were given
I clearly only put 2 arguments, out1 and out2, why does python think I'm giving 3 arguments?
I've tried this with a lambda function like:
l2dist = keras.layers.Lambda(lambda x,y: K.sqrt(K.sum((x-y)**2)))(out1,out2)
But I get the same error.