Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomCrop bugs #860

Open
martin-gorner opened this issue Sep 28, 2022 · 3 comments
Open

RandomCrop bugs #860

martin-gorner opened this issue Sep 28, 2022 · 3 comments

Comments

@martin-gorner
Copy link

martin-gorner commented Sep 28, 2022

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)

@bhack
Copy link
Contributor

bhack commented Sep 28, 2022

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

@bhack
Copy link
Contributor

bhack commented Sep 28, 2022

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)

@LukeWood
Copy link
Contributor

Thank you Martin for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants