5

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
today
  • 32,602
  • 8
  • 95
  • 115
olinarr
  • 261
  • 3
  • 13

1 Answers1

7

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])
today
  • 32,602
  • 8
  • 95
  • 115