Search code examples
keraskeras-layer

Visualizing results of preprocessing layers in keras


I have several image preprocessing steps built into my model:

model = Sequential()
model.add(Cropping2D(cropping=((22, 0), (0, 0)), input_shape=(160, 320, 3)))
model.add(Lambda(lambda image: tf.image.resize_images(image, (66, 200))))
model.add(Lambda(lambda image: image / 255.0 - 0.5))

The benefit of that approach is that the pipeline for training and testing is exactly the same. The disadvantage is that its rather difficult to verify the results of the preprocessing steps, e.g. by watching the images after the cropping step.

Is there a good way to do that in keras ?


Solution

  • You can easily get the outputs of any layer by using: model.layers[index].output and using K.function create a tensor function out of it and then evaluate the function and visualize the output.

    Check: Keras, How to get the output of each layer?