Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras 2: Using lambda function in "Merge" layers

I am trying to implement this merge layer:

policy = merge([out1, out2], mode = lambda x: x[0]-K.mean(x[0])+x[1], output_shape = (out_node,))

However, "merge" is no longer present in Keras 2. You can only access public standarized "Merge" layers, such as Add, Multiply, Dot.

How can I implement this function in Keras 2? I thought about making two merge layers but I have no idea how to implement that, especially because of the "K.mean" part.

For reference, here are the imports:

from keras.layers import merge
from keras import backend as K
like image 740
olinarr Avatar asked Apr 20 '19 09:04

olinarr


1 Answers

You can simply do this using a Lambda layer:

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

policy = Lambda(lambda x: x[0] - K.mean(x[0]) + x[1])([out1, out2])
like image 132
today Avatar answered Nov 07 '22 01:11

today