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 correctly using concatenate as per the paper.
- I am getting AttributeError: 'KerasTensor' object has no attribute 'add' on model4.add flatten. This error didn't show up earlier
- Earlier, the only error was ValueError: A
Concatenatelayer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 310, 1, 16), (None, 310, 1, 32), (None, 310, 1, 64)], which I am also not sure how to deal with.
model1= Sequential()
model2= Sequential()
model3= Sequential()
model4= Sequential()
input_sh = (619,2,1)
model1.add(Convolution1D(filters=16, kernel_size=21, padding='same', activation='LeakyReLU', 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='LeakyReLU', 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='LeakyReLU', input_shape= input_sh))
model3.add(MaxPooling2D(pool_size=(2,2), padding='same'))
model3.add(BatchNormalization())
model3.summary()
model4 = concatenate([model1.output, model2.output, model3.output], axis= -1)
model4.add(Flatten()) # Line with error
model4.add(Dense(2048, activation='tanh'))
model4.add(Dropout(.5))
model4.add(Dense(len(dic), activation="softmax")) #len(dic) = 19
model4.summary()
The output is as follows-
Model: "sequential_59"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_45 (Conv1D) (None, 619, 2, 16) 352
_________________________________________________________________
max_pooling2d_45 (MaxPooling (None, 310, 1, 16) 0
_________________________________________________________________
batch_normalization_45 (Batc (None, 310, 1, 16) 64
=================================================================
Total params: 416
Trainable params: 384
Non-trainable params: 32
_________________________________________________________________
Model: "sequential_60"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_46 (Conv1D) (None, 619, 2, 32) 384
_________________________________________________________________
max_pooling2d_46 (MaxPooling (None, 310, 1, 32) 0
_________________________________________________________________
batch_normalization_46 (Batc (None, 310, 1, 32) 128
=================================================================
Total params: 512
Trainable params: 448
Non-trainable params: 64
_________________________________________________________________
Model: "sequential_61"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_47 (Conv1D) (None, 619, 2, 64) 384
_________________________________________________________________
max_pooling2d_47 (MaxPooling (None, 310, 1, 64) 0
_________________________________________________________________
batch_normalization_47 (Batc (None, 310, 1, 64) 256
=================================================================
Total params: 640
Trainable params: 512
Non-trainable params: 128
_________________________________________________________________
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-bf7ad914aa4e> in <module>()
44 model4 = concatenate([model1.output, model2.output, model3.output], axis= -1)
45
---> 46 model4.add(Flatten())
47 model4.add(Dense(2048, activation='tanh'))
48 model4.add(Dropout(.5))
AttributeError: 'KerasTensor' object has no attribute 'add'