Is it possible to remove/replace the BOTTOM layers of a pretrained ResNet50 model in tf.keras.applications?
For instance, I've tried doing this:
import tensorflow as tf
pretrained_resnet = tf.keras.applications.ResNet50(include_top=False, weights='imagenet')
inputs = tf.keras.Input(shape=(256,256,1))
x = tf.keras.layers.ZeroPadding2D()(inputs)
x = tf.keras.layers.Conv2D(filters=64,
kernel_size=(7,7),
strides=(2,2),
padding='same')(x)
outputs = pretrained_resnet.layers[3](x)
test = tf.keras.Model(inputs, pretrained_resnet.output)
But it gives this error: ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_2:0", .......
I've also tried using the tf.keras Sequential API, but that doesn't work since ResNet isn't a sequential model. I'm basically just trying to replace the first Conv2D layer in ResNet50 with a new one. Is this possible? Or do I have to rewrite the entire ResNet model?
Any suggestions would be greatly appreciated!