Following the code given here for Visualizing Intermediate Representations, I am running:
successive_outputs = [layer.output for layer in CNN_model.layers]
visualization_model = tf.keras.models.Model(inputs=CNN_model.inputs, outputs=successive_outputs)
but keep getting the error ‘ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 200, 200, 3), dtype=tf.float32, name=‘random_flip_input’)…’
The model contains some data augmentation layers which I think are causing the issue. Model is built with:
CNN_model = tf.keras.Sequential([
tf.keras.layers.Rescaling(1. / 255),
data_augmentation,
# Add convolutions and max pooling
tf.keras.layers.Conv2D(16, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Conv2D(32, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Conv2D(64, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])
# Compile the model
CNN_model.compile(loss='binary_crossentropy', optimizer=RMSprop(),
metrics=[tf.keras.metrics.BinaryAccuracy(), tf.keras.metrics.Precision(name='precision')])
# Train the model
epochs = 1 # how long to train for
CNN_model.fit(
train_ds,
validation_data=val_ds,
epochs=epochs
)
What is the appropriate way for me to ignore the augmentation layers when trying to visualise the feature maps?