from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, GlobalAveragePooling2D, Dropout, concatenate, Dense
from tensorflow.keras.models import Model
from tensorflow.keras.applications import InceptionV3
from keras.backend import sigmoid
Define Swish activation function
def swish(x):
return x * sigmoid(x)
Define input layer
input_layer = Input(shape=(224, 224, 3))
Block 1
x = Conv2D(32, (3, 3), activation=swish, padding=’same’)(input_layer)
x = Conv2D(64, (3, 3), activation=swish, padding=’same’)(x)
x = MaxPooling2D((2, 2))(x)
Block 2
x = Conv2D(128, (3, 3), activation=swish, padding=’same’)(x)
x = Conv2D(256, (3, 3), activation=swish, padding=’same’)(x)
x = MaxPooling2D((2, 2))(x)
Global Average Pooling + Dropout
x = GlobalAveragePooling2D()(x)
x = Dropout(0.2)(x)
Add MaxPooling layer
x = MaxPooling2D((2, 2))(x)
Residual Blocks (4 times)
for _ in range(4):
residual = x
x = Conv2D(256, (3, 3), activation=swish, padding='same')(x)
x = Conv2D(256, (3, 3), activation=swish, padding='same')(x)
x = tf.keras.layers.add([x, residual])
Apply Global Average Pooling to the output of Residual Blocks
x = GlobalAveragePooling2D()(x)
InceptionV3
inception_model = InceptionV3(weights=’imagenet’, include_top=False, input_shape=(28, 28, 512))
inception_output = inception_model(x)
Global Average Pooling + Dropout
inception_output = GlobalAveragePooling2D()(inception_output)
inception_output = Dropout(0.2)(inception_output)
Concatenate the outputs
merged_output = concatenate([x, inception_output])
Apply softmax
output = Dense(4, activation=’softmax’)(merged_output)
Create the model
model = Model(inputs=input_layer, outputs=output)
Display the model summary
model.summary()
The error I am facing is ValueError: Input 0 of layer “max_pooling2d_2” is incompatible with the layer: expected ndim=4, found ndim=2. Full shape received: (None, 256) solve it and give me the anwsr and also use relu activation function
However, the error still persists. If anyone has experience with similar issues or can offer insight into resolving this problem, I’d be grateful for your help.
Thank you in advance for your time and assistance!
[Habibullah]
Habibullah khan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.