I am trying to drop the last layer and add a simple CNN instead like the following,
model = Sequential()
base_model = ResNet50V2(include_top=False, weights="imagenet", input_shape=input_shape, pooling="avg")
base_model.trainable = False
model = Sequential()
model.add(base_model)
# I want to add the following CNN
model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
model.add(MaxPooling2D((2, 2), padding='same'))
model.add(Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
model.add(MaxPooling2D((2, 2), padding='same'))
model.add(Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
model.add(MaxPooling2D((2, 2), padding='same'))
model.add(Flatten())
model.add(Dense(128, activation='relu', kernel_initializer='he_uniform'))
model.add(Dense(1, activation='sigmoid'))
I don't what I am missing in making this connection that I get the following error,
model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py", line 522, in _method_wrapper
result = method(self, *args, **kwargs)
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/sequential.py", line 228, in add
output_tensor = layer(self.outputs[0])
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 970, in __call__
input_list)
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1108, in _functional_construction_call
inputs, input_masks, args, kwargs)
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 840, in _keras_tensor_symbolic_call
return self._infer_output_signature(inputs, args, kwargs, input_masks)
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 878, in _infer_output_signature
self._maybe_build(inputs)
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 2600, in _maybe_build
self.input_spec, inputs, self.name)
File "/project/6035234/npiran/classification/venv_clf/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py", line 235, in assert_input_compatibility
str(tuple(shape)))
ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (None, 2048)