Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras merge layer warning

I'm keeping getting this warning:

lstm.py:119: UserWarning: The merge function is deprecated and will be removed after 08/2017. Use instead layers from keras.layers.merge, e.g. add, concatenate, etc. merged_vector = merge([l1, l2], mode=lambda x: (x[0] - x[1])**2, output_shape=lambda x: x[0]) /Library/Python/2.7/site-packages/keras/legacy/layers.py:456: UserWarning: The Merge layer is deprecated and will be removed after 08/2017. Use instead layers from keras.layers.merge, e.g. add, concatenate, etc. name=name)

Which is related to the following line of code:

merged_vector = merge([l1, l2], mode=lambda x: (x[0] - x[1])**2, output_shape=lambda x: x[0])

My model works fine, but how do I implement a custom merge in Keras 2.0.2? Thank you.

like image 947
Fernando Avatar asked Apr 01 '17 17:04

Fernando


1 Answers

Answering my own question:

# Custom Merge
def euclid_dist(v):
    return (v[0] - v[1])**2

def out_shape(shapes):
    return shapes[0]

merged_vector = Lambda(euclid_dist, output_shape=out_shape)([l1, l2])
like image 95
Fernando Avatar answered Nov 05 '22 21:11

Fernando