I load the saved model and for finetuning reason I add classification layers to the output of loaded model, So this what I write :
def create_keras_model():
model = tf.keras.models.load_model('model.h5', compile=False)
resnet_output = model.output
layer1 = tf.keras.layers.GlobalAveragePooling2D()(resnet_output)
layer2 = tf.keras.layers.Dense(units=256, use_bias=False, name='nonlinear')(layer1)
model_output = tf.keras.layers.Dense(units=2, use_bias=False, name='output', activation='relu')(layer2)
model = tf.keras.Model(model.input, model_output)
return model
but I find this error:
ValueError: Input 0 of layer global_average_pooling2d is incompatible with the layer: expected ndim=4, found ndim=2. Full shape received: [None, 128]
Can anyone please help me and tell me from what this error and how can I resolve this problem. Thanks!