I am using keras 2.02 and tensorflow 1.3 to build a convolution net with multiple sizes of filters. The code is shown below.
flts=100
kernel_sizes=[2,3,4]
submodels = []
for kw in kernel_sizes: # kernel sizes
submodel = Sequential()
submodel.add(embedding_layer)
submodel.add(Dropout(0.2))
submodel.add(Conv1D(filters=flts,
kernel_size=kw,
padding='same',
activation='relu'))
submodel.add(MaxPooling1D(pool_size=kw))
submodels.append(submodel)
big_model = Sequential()
#concat = Concatenate(axis=1) #line B
#big_model.add(concat(submodels)) #line C
big_model.add(Merge(submodels, mode="concat", concat_axis=1)) #line A
big_model.add(LSTM(units=100, return_sequences=True))
big_model.add(GlobalMaxPooling1D())
#big_model.add(Dropout(0.2))
big_model.add(Dense(2, activation='softmax'))
big_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
When using the deprecated code as on line A, it works ok. But when this is replaced by lines B,C, an error is generated as below:
--> 141 big_model.add(concat(submodels))
big_model.add = <bound method Sequential.add of <keras.models.Sequential object>>
concat = <keras.layers.merge.Concatenate object>
submodels = [<keras.models.Sequential object>, <keras.models.Sequential object>, <keras.models.Sequential object>]
142 big_model.add(LSTM(units=100, return_sequences=True))
143 big_model.add(GlobalMaxPooling1D())
144 #big_model.add(Dropout(0.2))
145 big_model.add(Dense(2, activation='softmax'))
........
/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in int_shape(x=<keras.models.Sequential object>)
404 (2, 2)
405 ```
406 """
407 if hasattr(x, '_keras_shape'):
408 return x._keras_shape
--> 409 shape = x.get_shape()
shape = undefined
x.get_shape = undefined
410 try:
411 return tuple([i.__int__() for i in shape])
412 except ValueError:
413 return None
AttributeError: 'Sequential' object has no attribute 'get_shape'
___________________________________________________________________
I don't know what I should do to fix this?
Thanks in advance