keras-cv
keras-cv copied to clipboard
RandomCrop bugs
Repro Colab here
Input image size: 360*512px
Problem #1: cropping to 128x513 crashes with a div by 0 Problem #2: cropping to 128x514 no longer produces random results (there are still many possible random positions along the Y axis)
Yes for # 1 it is an edge case of get_random_transformation
in Keras
https://github.com/keras-team/keras/blob/v2.10.0/keras/layers/preprocessing/image_preprocessing.py#L581-L582
w_start = rands[1] % (w_diff + 1)
As your image in the colab cell is
tf.Tensor([372 512 3], shape=(3,), dtype=int32)
With
random_crop = tf.keras.layers.RandomCrop(height=128, width=513)
You are going to have a w_diff
of -1
and so you crash with % 0
For # 2 I don't understand well the logic of using dtype.max
https://github.com/keras-team/keras/blob/v2.10.0/keras/layers/preprocessing/image_preprocessing.py#L580
rands = self._random_generator.random_uniform([2], 0, dtype.max, dtype)
Thank you Martin for the bug report!