获得同时使用Keras.layers.Add类错误()

问题描述 投票:0回答:1

我想添加的每个大小(None, 24, 24, 8)的2层,得到类的错误如下:

码:

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

请指教如何前进。我也试图把轴= 1或轴= -1,但没有奏效。

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

要么

x = Add()([layers[i-1],layers[i-9]], axis=-1)
merge keras add layer
1个回答
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])
© www.soinside.com 2019 - 2024. All rights reserved.