I loaded pretrained Resnet34 model in tensorflow. I want to insert a rescaling layer after the input layer and before the batch normalization layer.
resnet34 summary architecture is as bellow (My Tensorflow version is 2.9.0
):
I did that with this part of code, but the new model is not functional model. I need a new functional model, because after inserting rescaling layer, Also, I want to add some branches in the last convolutional layer of resnet34. I want to see which layer is connected to another layer.
import tensorflow as tf
tfk = tf.keras
tfkl = tf.keras.layers
from classification_models.tfkeras import Classifiers
resnet_34, preprocess_input = Classifiers.get('resnet34')
resnet_model = resnet_34(include_top=False,
weights='imagenet',
input_shape=(512, 512, 3))
rescaling_layer = tfkl.experimental.preprocessing.Rescaling(1/255, "rescaling")
for layer in resnet_model.layers:
layer.trainable = False
seqmodel = tf.keras.Sequential()
seqmodel.add(rescaling_layer)
seqmodel.add(resnet_model)
input_shape = (None, 512, 512, 3)
seqmodel.build(input_shape)
seqmodel.summary()
the output of my new model summary is as below which doesn't show me the resnet_model layers detail. Moreover the Connected to
column is missed in my new sequential model. I want to see which layer is connected to another layer.
Although, there are some solutions in other stack overflow pages close to my my case, But Those suggestions did not work, the final model of them still was a new sequential model which I don't want.
I will be grateful to see a python gist code as a solution.
Thanks in advance.