Skip to content Skip to sidebar Skip to footer

Keras Model Concat: Attribute And Value Error

This is a keras model I have made based on the paper Liu, Gibson, et al 2017 (https://arxiv.org/abs/1708.09022). It can be seen in fig1. I have 3 questions- I am not sure if I am

Solution 1:

You can use the Functional() API in order to solve your problem (I haven't read the paper, but here is how you can combine models and get a final output).

I used 'relu' activation for simplicity purposes (ensure you use keras inside tensorflow)

Here is the code that should work:

import tensorflow as tf
from tensorflow.keras import *
from tensorflow.keras.layers import *

model1= Sequential()
model2= Sequential()
model3= Sequential()

input_sh = (619,2,1)

model1.add(Convolution1D(filters=16, kernel_size=21, padding='same', activation='relu', input_shape=input_sh))
model1.add(MaxPooling2D(pool_size=(2,2), padding='same')) 
model1.add(BatchNormalization())
model1.summary()

model2.add(Convolution1D(filters=32, kernel_size=11, padding='same', activation='relu', input_shape= input_sh))
model2.add(MaxPooling2D(pool_size=(2,2), padding='same'))
model2.add(BatchNormalization())
model2.summary()

model3.add(Convolution1D(filters=64, kernel_size=5, padding='same', activation='relu', input_shape= input_sh))
model3.add(MaxPooling2D(pool_size=(2,2), padding='same'))
model3.add(BatchNormalization())
model3.summary()

concatenated = concatenate([model1.output, model2.output, model3.output], axis=-1)
x = Dense(64, activation='relu')(concatenated)
x = Flatten()(x)
x = Dropout(.5)(x)
x = Dense(19, activation="softmax")(x)
final_model = Model(inputs=[model1.input,model2.input,model3.input],outputs=x)
final_model.summary()





Model: "functional_3"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
conv1d_15_input (InputLayer)    [(None, 619, 2, 1)]  0                                            
__________________________________________________________________________________________________
conv1d_16_input (InputLayer)    [(None, 619, 2, 1)]  0                                            
__________________________________________________________________________________________________
conv1d_17_input (InputLayer)    [(None, 619, 2, 1)]  0                                            
__________________________________________________________________________________________________
conv1d_15 (Conv1D)              (None, 619, 2, 16)   352         conv1d_15_input[0][0]            
__________________________________________________________________________________________________
conv1d_16 (Conv1D)              (None, 619, 2, 32)   384         conv1d_16_input[0][0]            
__________________________________________________________________________________________________
conv1d_17 (Conv1D)              (None, 619, 2, 64)   384         conv1d_17_input[0][0]            
__________________________________________________________________________________________________
max_pooling2d_15 (MaxPooling2D) (None, 310, 1, 16)   0           conv1d_15[0][0]                  
__________________________________________________________________________________________________
max_pooling2d_16 (MaxPooling2D) (None, 310, 1, 32)   0           conv1d_16[0][0]                  
__________________________________________________________________________________________________
max_pooling2d_17 (MaxPooling2D) (None, 310, 1, 64)   0           conv1d_17[0][0]                  
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 310, 1, 16)   64          max_pooling2d_15[0][0]           
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 310, 1, 32)   128         max_pooling2d_16[0][0]           
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 310, 1, 64)   256         max_pooling2d_17[0][0]           
__________________________________________________________________________________________________
concatenate_5 (Concatenate)     (None, 310, 1, 112)  0           batch_normalization_15[0][0]     
                                                                 batch_normalization_16[0][0]     
                                                                 batch_normalization_17[0][0]     
__________________________________________________________________________________________________
dense_5 (Dense)                 (None, 310, 1, 64)   7232        concatenate_5[0][0]              
__________________________________________________________________________________________________
flatten_3 (Flatten)             (None, 19840)        0           dense_5[0][0]                    
__________________________________________________________________________________________________
dropout_3 (Dropout)             (None, 19840)        0           flatten_3[0][0]                  
__________________________________________________________________________________________________
dense_6 (Dense)                 (None, 19)           376979      dropout_3[0][0]                  
==================================================================================================
Total params: 385,779
Trainable params: 385,555
Non-trainable params: 224

Post a Comment for "Keras Model Concat: Attribute And Value Error"