使用 Keras.layers.Add() 时出现 class 错误
Getting class error while using Keras.layers.Add()
我正在尝试添加两层,每个层的大小为 (None, 24, 24, 8)
,但出现如下 class 错误:
代码:
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)
问题是您将层而不是张量传递到 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])
我正在尝试添加两层,每个层的大小为 (None, 24, 24, 8)
,但出现如下 class 错误:
代码:
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)
问题是您将层而不是张量传递到 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])