-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Added gray image support to adjust_saturation
function
#4480
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
I found that vision/test/test_transforms_tensor.py Line 70 in 9252436
|
@VinhLoiIT I think we can do the same trick with channels there |
For example: @pytest.mark.parametrize('device', cpu_and_gpu())
@pytest.mark.parametrize('channels', [3, 1])
class TestColorJitter:
@pytest.mark.parametrize('brightness', [0.1, 0.5, 1.0, 1.34, (0.3, 0.7), [0.4, 0.5]])
def test_color_jitter_brightness(self, brightness, device, channels):
tol = 1.0 + 1e-10
meth_kwargs = {"brightness": brightness}
_test_class_op(
T.ColorJitter, meth_kwargs=meth_kwargs, test_exact_match=False, device=device,
tol=tol, agg_method="max", channels=channels
)
# same of other tests cc @NicolasHug is it OK to do that like that with |
Sorry I'm missing some context. If you're asking whether we can add a parametrization for |
yes, I mean, do we have any restrictions on what we parametrize and where. Device parameter is something very generic and applicable to everyone. Channel as parameter is rather specific to |
Not really, we should just consider parametrizations to be glorified for-loops. If it makes sense to run a test with different values, then parametrization is relevant. In this specific case of |
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.
Thanks for the PR @VinhLoiIT
I left few nit comments, please fix them.
adjust_saturation
function
I don't know whether to update the documentation as well as channel testing of |
@VinhLoiIT @datumbox what about |
@vfdev-5 I'm writing tests for that now. Currently, the tests use vision/test/test_transforms.py Lines 1494 to 1503 in 4ef8e6b
which conflicts with my proposed changes as following: @pytest.mark.parametrize('num_ops', [1, 2, 3])
@pytest.mark.parametrize('magnitude', [7, 9, 11])
@pytest.mark.parametrize('fill', [None, 85, (128, 128, 128)])
@pytest.mark.parametrize('grayscale', [True, False])
def test_randaugment(num_ops, magnitude, fill, grayscale):
random.seed(42)
img = Image.open(GRACE_HOPPER)
if grayscale:
img = img.convert('L')
# conflict when fill=(128,128,128) and grayscale=True
transform = transforms.RandAugment(num_ops=num_ops, magnitude=magnitude, fill=fill)
for _ in range(100):
img = transform(img)
transform.__repr__() Do you have any suggestion here? |
@VinhLoiIT how about doing the following: if grayscale:
img = img.convert('L')
fill = (fill[0], ) if isinstance(fill, tuple) else fill |
@vfdev-5 Okay it works now. I'll update the tests soon. |
@VinhLoiIT FYI, some of the failing tests seems related:
|
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.
Thanks for the PR @VinhLoiIT.
The test failures look like a tolerance problem and might be resolved by adjusting it.
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.
LGTM from my side, I'll leave it to @vfdev-5 for the final approval and merge.
Thanks for the contribution @VinhLoiIT!
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 to me as well!
@VinhLoiIT thanks for the PR!
) Summary: * update channels parameter to every calling to check_functional_vs_PIL_vs_scripted * update adjust_saturation * update docstrings for functional transformations * parametrize channels * update docstring of ColorJitter class * move channels to class's parameter * remove testing channels for geometric transforms * revert redundant changes * revert redundant changes * update grayscale test cases for randaugment, autoaugment, trivialaugment * update docstrings of randaugment, autoaugment, trivialaugment * update docstring of ColorJitter * fix adjust_hue's docstring * change test equal tolerance * refactor grayscale tests * make get_grayscale_test_image private Reviewed By: datumbox Differential Revision: D31268053 fbshipit-source-id: 08dce692bbc86a1d0f471e54581600863a902c07
* update channels parameter to every calling to check_functional_vs_PIL_vs_scripted * update adjust_saturation * update docstrings for functional transformations * parametrize channels * update docstring of ColorJitter class * move channels to class's parameter * remove testing channels for geometric transforms * revert redundant changes * revert redundant changes * update grayscale test cases for randaugment, autoaugment, trivialaugment * update docstrings of randaugment, autoaugment, trivialaugment * update docstring of ColorJitter * fix adjust_hue's docstring * change test equal tolerance * refactor grayscale tests * make get_grayscale_test_image private [ghstack-poisoned]
* update channels parameter to every calling to check_functional_vs_PIL_vs_scripted * update adjust_saturation * update docstrings for functional transformations * parametrize channels * update docstring of ColorJitter class * move channels to class's parameter * remove testing channels for geometric transforms * revert redundant changes * revert redundant changes * update grayscale test cases for randaugment, autoaugment, trivialaugment * update docstrings of randaugment, autoaugment, trivialaugment * update docstring of ColorJitter * fix adjust_hue's docstring * change test equal tolerance * refactor grayscale tests * make get_grayscale_test_image private [ghstack-poisoned]
* update channels parameter to every calling to check_functional_vs_PIL_vs_scripted * update adjust_saturation * update docstrings for functional transformations * parametrize channels * update docstring of ColorJitter class * move channels to class's parameter * remove testing channels for geometric transforms * revert redundant changes * revert redundant changes * update grayscale test cases for randaugment, autoaugment, trivialaugment * update docstrings of randaugment, autoaugment, trivialaugment * update docstring of ColorJitter * fix adjust_hue's docstring * change test equal tolerance * refactor grayscale tests * make get_grayscale_test_image private
This resolves #4466
adjust_contrast
adjust_saturation
adjust_contrast
adjust_saturation
cc @vfdev-5 @datumbox