Home > database >  keras.layers.Concatenate gives 'NoneType' object is not subscriptable
keras.layers.Concatenate gives 'NoneType' object is not subscriptable

Time:12-12

When I try to concatenate my convolutional layers and LSTM layers. It noticed me that " 'NoneType' object is not subscriptable". How do I solve it ? I cannot understand why I can't concatenate them.

My code is like:

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)

It gives:

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

CodePudding user response:

It is because your y layers are not connected properly, try this:

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