π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
docs(augmentation): say RandomAutoContrast's clip_output has no effect (#4511)
Dipak Chaudhari41dbdd4c22cc
diff --git a/changelog.d/4511.fixed.md b/changelog.d/4511.fixed.mdnew file mode 100644index 000000000..f99528434--- /dev/null+++ b/changelog.d/4511.fixed.md@@ -0,0 +1,3 @@+`RandomAutoContrast` documents `clip_output` as having no effect: `normalize_min_max` already maps each channel+onto `[0, 1]`, so the clamp cannot change a value, including for inputs outside that range. It was described as+"if true clip output". A constant channel is documented to come back as zeros. (#4436)diff --git a/kornia/augmentation/_2d/intensity/auto_contrast.py b/kornia/augmentation/_2d/intensity/auto_contrast.pyindex 0b03cb917..8ba86b89c 100644--- a/kornia/augmentation/_2d/intensity/auto_contrast.py+++ b/kornia/augmentation/_2d/intensity/auto_contrast.py@@ -28,7 +28,10 @@ class RandomAutoContrast(IntensityAugmentationBase2D):Args:p: probability of applying the transformation.- clip_output: if true clip output+ clip_output: has no effect on the output. The transform is+ :func:`kornia.enhance.normalize_min_max`, which already maps each sample's channels onto ``[0, 1]``,+ so clamping to that interval cannot change a value -- including for inputs outside ``[0, 1]``. Kept+ for signature compatibility.same_on_batch: apply the same transformation across the batch.keepdim: whether to keep the output shape the same as input (True) or broadcast itto the batch form (False).@@ -37,7 +40,8 @@ class RandomAutoContrast(IntensityAugmentationBase2D):- Output: :math:`(B, C, H, W)`.. note::- This function internally uses :func:`kornia.enhance.normalize_min_max`+ This function internally uses :func:`kornia.enhance.normalize_min_max`. A channel with a single value+ has zero range and is returned as zeros."""diff --git a/tests/augmentation/test_augmentation.py b/tests/augmentation/test_augmentation.pyindex da975eec3..ced6d7e55 100644--- a/tests/augmentation/test_augmentation.py+++ b/tests/augmentation/test_augmentation.py@@ -5313,6 +5313,19 @@ class TestRandomAutoContrast(BaseTester):out = aug(x_data)assert out.shape == x_data.shape+ @pytest.mark.parametrize(("scale", "shift"), [(1.0, 0.0), (2.0, 0.0), (1.0, -1.0), (0.0, 0.5)])+ def test_clip_output_does_not_change_the_output(self, scale, shift, device, dtype):+ # #4436: normalize_min_max already lands in [0, 1], so the documented clamp is a no-op, even for the+ # out-of-range inputs a caller would reach for it to protect against. The constant image (scale 0)+ # comes back as zeros either way.+ torch.manual_seed(0)+ x = torch.rand(2, 3, 6, 8, device=device, dtype=dtype) * scale + shift+ clipped = kornia.augmentation.RandomAutoContrast(clip_output=True, p=1.0)(x.clone())+ unclipped = kornia.augmentation.RandomAutoContrast(clip_output=False, p=1.0)(x.clone())+ self.assert_close(clipped, unclipped, rtol=0.0, atol=0.0)+ assert unclipped.min().item() >= 0.0+ assert unclipped.max().item() <= 1.0+@pytest.mark.slowdef test_gradcheck(self, device):input = torch.rand(1, 2, 5, device=device, dtype=torch.float64)