I am running a code repository and I got an error message while recreate the model.
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 32, 32, 3), dtype=tf.float32, name='resnet50_input'), name='resnet50_input', description="created by layer 'resnet50_input'") at layer "resnet50". The following previous layers were accessed without issue:......
I am using Tensorflow 2.14.0 and Python 3.10
This is the test code,which I found is the code giving the error from the repo:
num_classes = 10
input_shape = (32, 32, 3)
model = tf.keras.Sequential()
base_model = tf.keras.applications.ResNet50(weights='imagenet', include_top=False, input_shape=input_shape)
for layer in base_model.layers:
layer.trainable = False
model.add(base_model)
model.add(tf.keras.layers.GlobalAveragePooling2D())
model.add(tf.keras.layers.Dense(num_classes, activation='softmax'))
extractor = tf.keras.Model(inputs=model.layers[0].input,
outputs=[layer.output for layer in model.layers])
I searched through Google and tried every methods. Some people said I should first create an input but still got the error with the code below. Can anyone give me a solution. I appreciate it.
num_classes = 10
input_shape = (32, 32, 3)
input_tensor = tf.keras.Input(shape=input_shape)
model = tf.keras.Sequential()
base_model = tf.keras.applications.ResNet50(weights='imagenet', include_top=False, input_shape=input_shape, input_tensor=input_tensor)
for layer in base_model.layers:
layer.trainable = False
model.add(base_model)
model.add(tf.keras.layers.GlobalAveragePooling2D())
model.add(tf.keras.layers.Dense(num_classes, activation='softmax'))
extractor = tf.keras.Model(inputs=model.layers[0].input,
outputs=[layer.output for layer in model.layers])