keras.layers.Concatenate 给出 'NoneType' 对象不可订阅

keras.layers.Concatenate gives 'NoneType' object is not subscriptable

当我尝试连接我的卷积层和 LSTM 层时。它注意到我“'NoneType' 对象不可订阅”。我该如何解决?我不明白为什么我不能连接它们。

我的代码是这样的:

x = inputI
x = keras.layers.Reshape((126,40,1))(x)
x = keras.layers.Conv2D(32, kernel_size=(3,3), activation='relu')(x)
x = keras.layers.Conv2D(32, kernel_size=(3,3),  activation='relu')(x)
x = keras.layers.MaxPooling2D(pool_size=(2,2))(x)
x = keras.layers.Conv2D(64, kernel_size=(3,3),  activation='relu')(x)  
x = keras.layers.Conv2D(64, kernel_size=(3,3),  activation='relu')(x)  
x = keras.layers.MaxPooling2D(pool_size=(2, 2))(x)
x = keras.layers.Flatten()(x)

y = inputE
y = keras.layers.LSTM(16, return_sequences=True)
y = keras.layers.Flatten()
y = keras.layers.Dense(2, activation='sigmoid')

z = keras.layers.Concatenate()([x,y])
z = keras.layers.Dense(100, activation='sigmoid')(z) 
z = keras.layers.Dense(10, activation='sigmoid')(z)

它给出:

TypeError                                 Traceback (most recent call last)
<ipython-input-45-2cb5d4fc2fb1> in <module>()
     18 y = keras.layers.Dense(2, activation='sigmoid')
     19 
---> 20 z = keras.layers.Concatenate()([x,y])
     21 z = keras.layers.Dense(100, activation='sigmoid')(z)
     22 z = keras.layers.Dense(10, activation='sigmoid')(z)

1 frames
/usr/local/lib/python3.7/dist-packages/keras/layers/merge.py in build(self, input_shape)
    495   def build(self, input_shape):
    496     # Used purely for shape validation.
--> 497     if not isinstance(input_shape[0], tuple) or len(input_shape) < 1:
    498       raise ValueError(
    499           'A `Concatenate` layer should be called on a list of '

TypeError: 'NoneType' object is not subscriptable

是因为你的y层没有连接好,试试这个:

y = inputE
y = keras.layers.LSTM(16, return_sequences=True)(y)
y = keras.layers.Flatten()(y)
y = keras.layers.Dense(2, activation='sigmoid')(y)