我试图添加两层,每层的大小为(None, 24, 24, 8)
,但出现类错误,如下所示:
代码:
x = add([layers[i-1],layers[i-9]])
或
x = Add()([layers[i-1],layers[i-9]])
错误:
/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**.
请告知如何前进。我还尝试将axis = 1或axis = -1放进去,但是没有用。
x = Add()([layers[i-1],layers[i-9]],axis=1)
或
x = Add()([layers[i-1],layers[i-9]], axis=-1)
答案 0 :(得分:1)
问题是您正在传递层而不是张量传递到Add()
层。我想您的代码中某处有一个Input()
层。您需要将此输入传递给其他层。您的代码应该看起来像这样:
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])