Skip to content

RandomCrop bugs #860

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

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

RandomCrop bugs #860

martin-gorner opened this issue Sep 28, 2022 · 4 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!

@sachinprasadhs
Copy link
Collaborator

Thanks for reporting the issue! We have consolidated the development of KerasCV into the new KerasHub package, which supports image, text, and multi-modal models. Please read the announcement. KerasHub will support all the core functionality of KerasCV.

KerasHub can be installed with !pip install -U keras-hub. Documentation and guides are available at keras.io/keras_hub.

With our focus shifted to KerasHub, we are not planning any further development or releases in KerasCV. If you encounter a KerasCV feature that is missing from KerasHub, or would like to propose an addition to the library, please file an issue with KerasHub.

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