3

In keras 1 i used to write

def merge_mode(branches):
   return #merge function

Merge([...], output_shape=(num_classes,), mode=merge_mode)

But now in keras 2.0 Merge is deprecated, and you can only add predefined functions like add, average, concatenate, ....

My question is how can i add a custom merge function in keras 2.0

A. AB
  • 31
  • 2

1 Answers1

1

If you're looking for a layer that has no trainable weights, which from your looking at your example, I guess is the case. Then you can use a Lambda layer.

I actually wrote one myself to create a siamese CNN using a squared distance measure. See example below:

from keras.layers import Lambda

# I create the layer structure first.
# This can then be added to a sequential model or used in a functional model.
merge_layer = Lambda(lambda x: K.square(x[0]-[x]), output_shape=lambda x: x[0])

# Inside a functional model you would use it like this:
block_output = merge_layer([left,right])
Willem Meints
  • 1,152
  • 14
  • 33