DeepCCA icon indicating copy to clipboard operation
DeepCCA copied to clipboard

Problem with merging models and building them

Open cborelc opened this issue 6 years ago • 6 comments

Hi: I took the code from GitHub and ran it in an Anaconda environment that has Keras 2.4.2 installed and ran into the following error:

runfile('M:/mypython/DeepCCA-master/DeepCCA.py', wdir='M:/mypython/DeepCCA-master') Reloaded modules: utils, linear_cca loading data ... loading data ... Traceback (most recent call last):

File "", line 1, in runfile('M:/mypython/DeepCCA-master/DeepCCA.py', wdir='M:/mypython/DeepCCA-master')

File "C:\anaconda3\envs\keras\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace)

I tried to change the line containing "Merge" to "from keras.layers import Dense, merge" and the line to calling it to "merge" - that created the error:

File "M:\mypython\DeepCCA-master\models.py", line 19, in create_model model.add(merge([view1_model, view2_model], mode='concat'))

TypeError: 'module' object is not callable

Then I added "Concatenate" to the input and changed the line to "model.add(Concatenate([view1_model, view2_model]))". Now the data was loading OK but it failed when running "model.summary()" with:

File "C:\anaconda3\envs\keras\lib\site-packages\keras\engine\network.py", line 1252, in summary 'This model has not yet been built. '

ValueError: This model has not yet been built. Build the model first by calling build() or calling fit() with some data. Or specify input_shape or batch_input_shape in the first layer for automatic build.

Now I am at a loss how to proceed - I havn't used Keras until now. Thanks

File "C:\anaconda3\envs\keras\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "M:/mypython/DeepCCA-master/DeepCCA.py", line 153, in learning_rate, reg_par, outdim_size, use_all_singular_values)

File "M:\mypython\DeepCCA-master\models.py", line 19, in create_model model.add(Merge([view1_model, view2_model], mode='concat'))

NameError: name 'Merge' is not defined

cborelc avatar Nov 01 '18 14:11 cborelc

Try concatenate instead of Concatenate, merge or Merge. It worked for me.

rickerish-nah avatar Nov 07 '18 18:11 rickerish-nah

Hi cbrelc, I got the same problem! I am testing the same code that you are testing. I got the same error: NameError: name 'Merge' is not defined,

though I have changed "Merge" to "concatenate". model.add(concatenate([view1_model, view2_model]))

Not sure what happened...

fzhangcode avatar Nov 20 '18 15:11 fzhangcode

#10 I hope this will help.

Cugtyt avatar Jan 18 '19 03:01 Cugtyt

model.add(concatenate([view1_model, view2_model])) Got a syntax error SyntaxError: invalid syntax

ghost avatar Feb 28 '19 08:02 ghost

I'm facing the same issue, I've tried some fixes with concatenate, merge etc, but none of them worked.. Please help

swathi-vennela avatar May 09 '21 06:05 swathi-vennela

I also have a problem with concatenate:

File "C:\Users\hamid\PycharmProjects\pythonProject\venv\lib\site-packages\keras\layers\merging\concatenate.py", line 95, in build if len(input_shape) < 1 or not isinstance(input_shape[0], tuple): TypeError: object of type 'NoneType' has no len()

hamidialii1990 avatar Mar 29 '23 09:03 hamidialii1990