abcdefghi019283
abcdefghi019283

Reputation: 105

Concatenate two output layers of same dimension

I have two hidden layers of dimension 50 from 2 different autoencoder models. The shape is [None,50] for both of them. But when executing the following code:

concat_layer = Concatenate()([_1.layers[7], _2.layers[11]])
softmax_layer = keras.layers.Dense(2, activation='softmax')(concat_layer)
sum_model = keras.models.Model(inputs=[_1_x_train, _2_x_train], outputs=softmax_layer)
sum_model.compile(optimizer='Adam', loss='mse')

I get the Error: TypeError: 'NoneType' object is not subscriptable for Concatenate()([_1.layers[7], _2.layers[11]])

Edit: Here is the layer structure of the two models.

_1 summary:

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 500)]             0         
_________________________________________________________________
dense (Dense)                (None, 250)               125250    
_________________________________________________________________
dropout (Dropout)            (None, 250)               0         
_________________________________________________________________
dense_1 (Dense)              (None, 100)               25100     
_________________________________________________________________
dropout_1 (Dropout)          (None, 100)               0         
_________________________________________________________________
dense_2 (Dense)              (None, 50)                5050      
_________________________________________________________________
dropout_2 (Dropout)          (None, 50)                0         
_________________________________________________________________
dense_3 (Dense)              (None, 50)                2550      
_________________________________________________________________
dense_4 (Dense)              (None, 100)               5100      
_________________________________________________________________
dense_5 (Dense)              (None, 250)               25250     
_________________________________________________________________
dense_6 (Dense)              (None, 500)               125500    
=================================================================

_2 summary:

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 24765)]           0         
_________________________________________________________________
dense (Dense)                (None, 5000)              123830000 
_________________________________________________________________
dropout (Dropout)            (None, 5000)              0         
_________________________________________________________________
dense_1 (Dense)              (None, 2500)              12502500  
_________________________________________________________________
dropout_1 (Dropout)          (None, 2500)              0         
_________________________________________________________________
dense_2 (Dense)              (None, 1000)              2501000   
_________________________________________________________________
dropout_2 (Dropout)          (None, 1000)              0         
_________________________________________________________________
dense_3 (Dense)              (None, 500)               500500    
_________________________________________________________________
dense_4 (Dense)              (None, 250)               125250    
_________________________________________________________________
dense_5 (Dense)              (None, 100)               25100     
_________________________________________________________________
dense_6 (Dense)              (None, 50)                5050      
_________________________________________________________________
dense_7 (Dense)              (None, 50)                2550      
_________________________________________________________________
dense_8 (Dense)              (None, 100)               5100      
_________________________________________________________________
dense_9 (Dense)              (None, 250)               25250     
_________________________________________________________________
dense_10 (Dense)             (None, 500)               125500    
_________________________________________________________________
dense_11 (Dense)             (None, 1000)              501000    
_________________________________________________________________
dense_12 (Dense)             (None, 2500)              2502500   
_________________________________________________________________
dense_13 (Dense)             (None, 5000)              12505000  
_________________________________________________________________
dense_14 (Dense)             (None, 24765)             123849765 
=================================================================

I have to add something here because otherwise the changes will not be accepted because its only 'code' i added.

Upvotes: 1

Views: 70

Answers (1)

Kaveh
Kaveh

Reputation: 4960

This error indicates, it is trying to get subscript (object[index]) of an object which is NoneType.

The input to atf.keras.layers.Concatenate() layer should be a tensor. But you have passed layer instances. So instead of passing layers, pass their output like this:

concat_layer = Concatenate()([_1.layers[7].output, _2.layers[11].output])

In addition, your model definition should change, since you have passed input data as inputs, instead of the first layers. Get the models input layer by model.input. So modified code should be like this:

#sum_model = keras.models.Model(inputs=[_1_x_train, _2_x_train], outputs=softmax_layer)
sum_model = keras.models.Model(inputs=[_1.input, _2.input], outputs=softmax_layer)

You should pass input data to model.fit().

Upvotes: 1

Related Questions