0
votes

I am facing this error in Keras 2. How can I resolve it? I have imported

from keras.layers import Input, merge

[...]

 up1 = merge([UpSampling2D(size=(2, 2))(conv3), conv2], mode='concat', concat_axis=1)
    /usr/local/python/3.5.2-gcc4/externalmodules/lib/python3.5/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)
Traceback (most recent call last):
  File "./src/retinaNN_training.py", line 171, in <module>
    model = get_unet(n_ch, patch_height, patch_width)  #the U-net model
  File "./src/retinaNN_training.py", line 53, in get_unet
    up1 = merge([UpSampling2D(size=(2, 2))(conv3), conv2], mode='concat', concat_axis=1)
  File "/usr/local/python/3.5.2-gcc4/externalmodules/lib/python3.5/site-packages/keras/legacy/layers.py", line 456, in merge
    name=name)
  File "/usr/local/python/3.5.2-gcc4/externalmodules/lib/python3.5/site-packages/keras/legacy/layers.py", line 107, in __init__
    node_indices, tensor_indices)
  File "/usr/local/python/3.5.2-gcc4/externalmodules/lib/python3.5/site-packages/keras/legacy/layers.py", line 187, in _arguments_validation
    'Layer shapes: %s' % (input_shapes))
ValueError: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 2, 24, 128), (None, 1, 24, 64)]

How can I convert the merge function to be readable on Keras 2.x.x.? Thanks

1
By the message Layer shapes: [(None, 2, 24, 128), (None, 1, 24, 64)] you have to adjust the shapes of what you're passing to the merge. It's simply impossible to merge those. You "probably" should have both ending in 128 or both ending in 64.Daniel Möller
@Daniel thanks for message, but this is not shape problem, it is incompatibility between Keras 1 and Keras 2 . An I do not know how to solve this.S.EB
Well, that's what the error says.... if you could share the code for your entire model we could try to find the problem.Daniel Möller

1 Answers

0
votes

It seems that you are using Keras version above 1.0.3. Versions after 1.0.3 use tensorflow as backend by default Github Issues. So you can do two things:

  1. Install 1.0.3 Version of Keras. [OR]

pip install https://github.com/fchollet/keras/tarball/1.0.3

  1. Modify ~/.keras/keras.json so that it looks like

{ "image_dim_ordering": "th", "epsilon": 1e-07, "floatx": "float32", "backend": "tensorflow" }