0

Is it possible to verify the output of

Cropping2D(cropping=((22, 0), (0, 0)), 
                     input_shape=resized_image.shape)

Without constructing and training a model? I.e. I just want to pass and image to Cropping and get and display the output image.

Oblomov
  • 8,953
  • 22
  • 60
  • 106

1 Answers1

1

Yes, this is described in the Keras FAQ. To quote:

from keras import backend as K

# with a Sequential model
get_3rd_layer_output = K.function([model.layers[0].input],
                                  [model.layers[3].output])
layer_output = get_3rd_layer_output([X])[0]

This example assumes that your Cropping layer has index 3. You need to substitute this index with the correct number according to your model.

nemo
  • 55,207
  • 13
  • 135
  • 135
  • Thanks - I asume [X] in layer_output = get_3rd_layer_output([X])[0] would be the image? – Oblomov Jan 29 '17 at 20:13
  • Yes. Note that if you are using layers that utilize the learning phase, i.e. have different behavior for training and prediction, you need to supply the image and a 0/1 depending on the phase (1=learning phase, 0=eval. phase). – nemo Jan 30 '17 at 00:58
  • Ok, the snippet is a bit cumbersome and looks more like a workaround than a feature, but I tried it and it works. – Oblomov Jan 30 '17 at 06:30