Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't import keras.layers.Merge

Tags:

python

keras

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?

like image 459
boltzsman Avatar asked Jun 25 '18 20:06

boltzsman


People also ask

How to merge layers in keras 2?

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.).

What is the use of Keras concatenate layer?

tf.keras.layers.Concatenate(axis=-1, **kwargs) Layer that concatenates a list of inputs. It takes as input a list of tensors, all of the same shape except for the concatenation axis, and returns a single tensor that is the concatenation of all inputs.

What is the use of multiply in keras?

keras.layers.Multiply () It is the layer that performs element-wise multiplication operation on a list of inputs by taking the similar shape of the tensors list as an input and returns an individual tensor of the same shape.


3 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

like image 59
ascripter Avatar answered Oct 21 '22 16:10

ascripter


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
like image 2
Khossen Avatar answered Oct 21 '22 14:10

Khossen


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

like image 1
Kukesh Avatar answered Oct 21 '22 15:10

Kukesh