0

I am trying to add two layers each of size (None, 24, 24, 8) but getting the class error as below:

Code:

x = add([layers[i-1],layers[i-9]])

or

x = Add()([layers[i-1],layers[i-9]])

Error:

/keras_222/local/lib/python2.7/site-packages/keras/engine/base_layer.py", line 285, in assert_input_compatibility
    str(inputs) + '. All inputs to the layer '
ValueError: Layer add_1 was called with an input that isn't a symbolic tensor. **Received type: <class** 'keras.layers.normalization.BatchNormalization'>. Full input: [<keras.layers.normalization.BatchNormalization object at 0x7f04e4085850>, <keras.layers.normalization.BatchNormalization object at 0x7f050013cd10>]. All inputs to the **layer should be tensors**.

Please advise how to move forward. I also tried putting axis=1 or axis=-1 but it didn't work.

x = Add()([layers[i-1],layers[i-9]],axis=1)

or

x = Add()([layers[i-1],layers[i-9]], axis=-1)
Anna Krogager
  • 3,528
  • 16
  • 23
runner
  • 15
  • 2

1 Answers1

1

The problem is that you are passing layers instead of tensors to your Add() layer. I suppose you have an Input() layer somewhere in your code. You need to pass this input through your other layers. Your code should instead look something like this:

input = Input(shape)
# pass input through other intermediate layers first if needed

output_1 = layers[i-1](input)
output_2 = layers[i-9](input)

x = Add()([output_1, output_2])
Anna Krogager
  • 3,528
  • 16
  • 23