Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading