-
Notifications
You must be signed in to change notification settings - Fork 332
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
RandomResizedCrop API Change #676
Comments
My understanding is as follows:
Is this procedure correct? If this is incorrect, could you please jot down the procedure in the same way as above to avoid any confusion? /cc @sayakpaul |
either less or greater than one. 150x200 zoomed by 2 should crop a 75x100 region, so it is zoomed to double the size
I guess to get the desired effect, zoom_factor => should be inversed before multiplying. so a zoom factor of 2 => 0.5 and vice versa. This means a zoom factor of 0.5 zooms out, 2.0 zooms in.
yep! zoom_Factor 1.0 and aspect ratio 1.0 should just be the same as random crop basically. Sound good? |
Okay. Zoom factor is almost clear to me now. Assuming we use a zoom factor of 0.5 (which will zoom out the image) we get a 600x800 image, right? How would the image look like? Will the image repeat itself or is it just a normal resize? |
you will get a 600x800 crop, but then it will be resized BACK to 224x244. So zoom is computed based on crop size. Imagine a 1000x1000 image with a crop size of 200x200. If you sample zoom factor 0.5, your crop size will be 400x400, then you will be resized back to 200x200. |
An exact process: target_size, zoom_factor, aspect_ratio_factor. the process starts and a value is sampled from zoom_factor:
next, crop size is calculated using target size and zoom:
next, aspect_ratio is applied:
take a crop of crop_size:
|
Thanks for this, it really helps! I have two concerns regarding this approach:
|
Thanks for this, it really helps! I have two concerns regarding this approach:
Any reason why not? If the goal of the layer is to take zooms with a level of distortion, it should be easy to tune the distortions relative to the result.
The nice thing about |
@martin-gorner has more thoughts on this too |
Toughts:
I think I prefer the solution without black bars for two reasons:
|
I like this thought experiment. Tremendous one. |
@AdityaKane2001 is this clear now? |
@LukeWood Yup, got it. I'll create a PR for this over the weekend. |
@martin-gorner @LukeWood @sayakpaul
To avoid this case, I'll just clip the |
you cannot clip crop_resize without introducing image distorsions. Remember
that the final image size is fixed for all images which also means a fixed
aspect ratio. If you clip crop_resize at any point, you change the aspect
ratio. The only way to get it back is to distort the image. When the user
specifies "no distorsinos", there should be no distorsions.
…On Tue, 23 Aug 2022 at 09:29, Aditya Kane ***@***.***> wrote:
@martin-gorner <https://github.com/martin-gorner> @LukeWood
<https://github.com/LukeWood> @sayakpaul <https://github.com/sayakpaul>
An edge case not yet considered is what happens when the computed
crop_size ends up being larger, in at least one dimension, than the image.
To avoid this case, I'll just clip the crop_size values to the image
dimensions. It seems to have the same effect as
layers.Resizing(crop_to_aspect_ratio=True). Moreover it will intuitively
handle the case where both dimensions of crop_size are larger than the
image dimensions. WDYT?
—
Reply to this email directly, view it on GitHub
<#676 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHKKZ7HIH744C77PT7V3SLV2R4VLANCNFSM556HBLCQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Martin Görner | Product Manager, TensorFlow & Keras | ***@***.*** | +1
425 273 0605
|
Understood. I guess I will rewrite the implementation and drop |
I think tf.image.crop_and_resize should work fine. You just have to pass it the correct crop boxes. |
Currently, RandomResizedCrop is tuned by taking a crop_area_factor and aspect_ratio_factor.
The API should be updated to take a target_size, zoom_factor, and an aspect ratio factor. At augmentation time, a value is drawn randomly from the Zoom factor and aspect ratio factor distributions. a crop size is computed by multiplying each dimension of target size with the value drawn from zoom_factor. Next, the width and height of the crop size are distorted accordingly by the value drawn from the aspect ratio factor. A crop of this size is taken from the image, and finally is resized to the target size.
Some edge cases:
The text was updated successfully, but these errors were encountered: