I am new to python and am working on an image processing project and built the below model. I get the error posted below the model.
In my research, I found some answers regarding this error:
Merge 2 sequential models in Keras the issue above is of Concatenate 2 models not Concatenate 2 layers
https://keras.io/getting-started/functional-api-guide/#multi-input-and-multi-output-models In the keras example, Concatenate 2 layers but 1 layer is an input layer. I would like to understand how to Concatenate 2 regular layers and use the concatenated layer as a layer in a sequence of layers. similar concept to the Inception Model.
input
/ | \
a1 b1 c1
| | |
a2 b2 c2
\ | /
concatenate
/ | \
d1 e1 f1
| | |
d2 e2 f2
\ | /
output
above is my attempt to draw what my final goal :)
def fet_Model():
bnd_input = Input(shape=input_shape)
k31 = Conv2D(128, kernel_size=(3, 3), activation='relu', padding='same')(bnd_input)
k31 = Conv2D(128, kernel_size=(3, 3), activation='relu', padding='same')(k31)
k31 = MaxPooling2D(pool_size=(3, 3), strides=(2, 2))(k31)
in_ly1_cv_1n1 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(k31)
in_ly1_cv_3n3 = Conv2D(64, kernel_size=(3, 3), activation='relu', padding='same')(in_ly1_cv_1n1)
in_ly1_cv_5n5 = Conv2D(64, kernel_size=(5, 5), activation='relu', padding='same')(in_ly1_cv_1n1)
in_ly1_mx_pl = MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='same')(k31)
in_ly1_mxcv_1n1 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(in_ly1_mx_pl)
filt_concat1 = Concatenate([in_ly1_mxcv_1n1, in_ly1_cv_5n5, in_ly1_cv_3n3, k31])
# when running the below line I receive the error
in_ly2_cv_1n1 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(filt_concat1)
in_ly2_cv_3n3 = Conv2D(64, kernel_size=(3, 3), activation='relu', padding='same')(in_ly2_cv_1n1)
in_ly2_cv_5n5 = Conv2D(64, kernel_size=(5, 5), activation='relu', padding='same')(in_ly2_cv_1n1)
in_ly2_mx_pl = MaxPooling2D(pool_size=(3, 3), strides=(1, 1))(filt_concat1)
in_ly2_mxcv_1n1 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(in_ly2_mx_pl)
filt_concat2 = Concatenate([in_ly2_mxcv_1n1, in_ly2_cv_5n5, in_ly2_cv_3n3, k31])
lst_ly_avg_pl = AveragePooling2D(pool_size=(3, 3), strides=(2, 2))(filt_concat2)
lst_ly_cnv2 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(lst_ly_avg_pl)
lst_ly_den = Dense(1, activation='sigmoid')(lst_ly_cnv2)
model = Model(inputs=bnd_input, outputs=lst_ly_den)
optimizer = Adam(lr= 0.002, beta_1=0.99, beta_2=0.999, epsilon=1e-08, decay=0.01)
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
return model
Error:
Traceback (most recent call last):
K.is_keras_tensor(x)
raise ValueError('Unexpectedly found an instance of type `' +
str(type(x)) + '`. '
ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-194-ebff784b774c>", line 1, in <module>
in_ly2_cv_1n1 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(filt_concat1)
self.assert_input_compatibility(inputs)
str(inputs) + '. All inputs to the layer '
ValueError: Layer conv2d_41 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.merge.Concatenate'>. Full input: [<keras.layers.merge.Concatenate object at 0x1cee082b0>]. All inputs to the layer should be tensors.