can't import keras.layers.Merge

Question:

I want to merge two LSTM models in Keras. I have seen many examples of importing Merge as:

from keras.layers import Merge

When I do this, I get an import error.

ImportError: cannot import name 'Merge'.

Has there been some refactor and now Merge is elsewhere?

Asked By: boltzsman

||

Answers:

As of keras 2, the module keras.layers.merge doesn’t have a generic public Merge-Layer. Instead you are supposed to import the subclasses like keras.layers.Add or keras.layers.Concatenate etc. directly (or their functional interfaces with the same names lowercase: keras.layers.add, keras.layers.concatenate etc.).

See what types of merging layers exist in the keras docs

Edit: tf.keras.layers.Add etc. would now be the correct import path using tf.keras inside tensorflow – since keras 2.3.0 (Sep 2019), this is the developer’s official recommendation:

This is also the last major release of multi-backend Keras. Going forward, we recommend that users consider switching their Keras code to tf.keras in TensorFlow 2.0.

Answered By: ascripter

Cause : case sensitive
change it
from keras.layers import Merge
to
from keras.layers import merge

Answered By: Kukesh
from keras.layers import InputLayer, Activation, Merge, Concatenate,Input

write to below code:only change small letter(merge)

from keras.layers import InputLayer, Activation, merge, Concatenate,Input
Answered By: Khossen
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.