-
Notifications
You must be signed in to change notification settings - Fork 333
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
Implement RandomResizedCrop layer #131
Comments
Yeah, I agree RandomResizedCrop should be included. |
@sayakpaul @LukeWood If the above layer is the desired layer for the above request, then you may want to take a look at this. |
that layer doesn't fill the need because the Resize portion is also important. RandomResizedCrop basically stretch and crop images randomly. |
something like this? tf.keras.layers.RandomCrop
tf.keras.layers.Resizing |
So: passing |
Sorry, didn't catch your concern. Could you elaborate? Like, are you saying that after passing the input to resize a layer, the shape of the output tensor becomes |
We do also need to remember that this layer needs to handle more than 1 sample i.e., an arbitrary number of images having a uniform shape. |
Precisely, because each individual image should be augmented independently. So they will have random sizes. |
They’d be a RaggedTensor really, which is a bad UX |
With random resized crops, I think we are able to cover many different transformations composed into one: random zooming random translation, resizing, etc. |
@LukeWood I passed some tensor to resize the layer, but it didn't give ragged output. What have I missed? resize = tf.keras.layers.Resizing(224, 224)
sample = tf.ones(shape=(5, 100, 100, 3))
resize(sample).shape
TensorShape([5, 224, 224, 3])
sample = tf.ones(shape=(5, 100, 100, 3))
rand_crop = tf.keras.layers.RandomCrop(64, 64)
rand_crop(sample).shape
TensorShape([5, 64, 64, 3]) |
@sayakpaul @LukeWood simple_aug = tf.keras.Sequential(
[
tf.keras.layers.RandomCrop(224, 224),
tf.keras.layers.Resizing(512, 512)
]
) |
Hi team. If no one is working on this, I would like to work on the same. |
I agree. The most difficult part is to come up with a batched implementation. Correct me if I'm wrong, but I believe this is the procedure:
These tasks are straightforward for a single image, however are difficult for a batch of images. The torch implementation takes a slight shortcut: it uses the same aspect ratio and cropping vertices for all images in the batch. See here. If that approach seems acceptable, a TF implementation is achievable as well. |
@AdityaKane2001 we had a discussion about the randomizzation in the batch at #146 |
Hi! I would love to work on this. I already have a batched, frame-wise random implementation for personal use here. My steps were the following:
This implementation however should subclass |
The issue with this implementation is that it only takes crops with the same resolution. If your input images are 448x448 for example, you will always see 25% of their area, resized to a higher resolution. We want to sample crops with different resolutions, and resize them to the same resolution. |
Hey there! Your starting implementation looks great. Feel free to open a PR. You don’t need to handle any inputs outside of images and labels to get merged. We can add boxes in a follow up. Feel free to open a PR! |
The rescales should also be random, but feel free to push a starter implementation to a PR. I am also happy to contribute some commits to this effort once the PR is open! @beresandras |
* add transposed convolution layer * fix comments
Randomly resized cropping is pretty much a standard augmentation transformation that is used to train vision models. Recently, a team at Facebook also showed why it's often necessary to include this transformation for better generalization [1].
An implementation of this layer in PyTorch is available as
RandomResizedCrop
.References:
[1] https://arxiv.org/abs/2106.05121
The text was updated successfully, but these errors were encountered: