-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[prototype] Speed up adjust_contrast_image_tensor
#6933
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
Conversation
if c == 3: | ||
grayscale_image = _rgb_to_gray(image, cast=False) | ||
if not fp: | ||
grayscale_image = grayscale_image.floor_() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmeier In an early iteration of the PR, I have missed this floor_()
call which is necessary to reproduce identical results with stable. Unfortunately the tests passed without catching the issue. Might be worth checking that our reference tests check both on floats and ints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is properly tested with
vision/test/prototype_transforms_kernel_infos.py
Lines 1845 to 1850 in f32600b
def reference_inputs_adjust_contrast_image_tensor(): | |
for image_loader, contrast_factor in itertools.product( | |
make_image_loaders(color_spaces=(features.ColorSpace.GRAY, features.ColorSpace.RGB), extra_dims=[()]), | |
_ADJUST_CONTRAST_FACTORS, | |
): | |
yield ArgsKwargs(image_loader, contrast_factor=contrast_factor) |
but it seems our tolerances are to high to pick up on this
vision/test/prototype_transforms_kernel_infos.py
Line 1866 in f32600b
closeness_kwargs=DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS, |
vision/test/prototype_transforms_kernel_infos.py
Lines 64 to 67 in f32600b
DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS = { | |
(("TestKernels", "test_against_reference"), torch.float32, "cpu"): dict(atol=1e-5, rtol=0, agg_method="mean"), | |
(("TestKernels", "test_against_reference"), torch.uint8, "cpu"): dict(atol=1e-5, rtol=0, agg_method="mean"), | |
} |
However, we can't remove the tolerances completely here, since the output differs even with the current implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... 99% of the performance optimizations were tested for training and we know they are correct. So there might be rounding error issues. I think we should adjust the tolerances to the degree that will catch BC issues but not go ballistic for the 8th decimal. That might be a hard exercise though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks @datumbox
@vfdev-5 thanks. It seems there is an unrelated flaky test about resizing bboxes: Could you have a look?
|
Summary: * Avoid double casting on adjust_contrast * Handle properly ints. Reviewed By: NicolasHug Differential Revision: D41265198 fbshipit-source-id: 4bacdc743b3cdf55a43e0ca6185b9c9b2ab12160
Related to #6818
Small performance improvement for uint8 images by avoiding the double casting from floats to ints and back to floats.
Floats remain unaffected, a 5% boost on uint8s:
cc @vfdev-5 @bjuncek @pmeier