π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
docs(augmentation): make three Args blocks match their constructors (#4490)
Dipak Chaudhari2676489e7ce2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 081d16935..9d88e4b93 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -407,6 +407,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Bug fixes+* The `Args` blocks of `ColorJitter`, `RandomBrightness` and `RandomGaussianBlur` no longer document a+ `silence_instantiation_warning` argument that none of them accepts, and `ColorJitter` now documents its+ `order` argument: a fixed (sub)set of brightness/contrast/saturation/hue indices that makes the transform+ `torch.compile` fullgraph-safe, with the drawn `_params["order"]` entry ignored when it is set.+ (#4437, #4490)+* `kornia.enhance.equalize`, `equalize3d`, `RandomEqualize` and `RandomEqualize3D` raise a `RuntimeError` namingthe `[0, 1]` input range for values the 256-bin lookup cannot index, instead of a raw`index 259 is out of bounds for dimension 1 with size 256` from the gather. The check usesdiff --git a/kornia/augmentation/_2d/intensity/brightness.py b/kornia/augmentation/_2d/intensity/brightness.pyindex d13c58a5c..bd833c025 100644--- a/kornia/augmentation/_2d/intensity/brightness.py+++ b/kornia/augmentation/_2d/intensity/brightness.py@@ -35,7 +35,6 @@ class RandomBrightness(IntensityAugmentationBase2D):Args:brightness: the brightness factor to applyclip_output: if true clip output- silence_instantiation_warning: if True, silence the warning at instantiation.same_on_batch: apply the same transformation across the batch.p: probability of applying the transformation.keepdim: whether to keep the output shape the same as input (True) or broadcast itdiff --git a/kornia/augmentation/_2d/intensity/color_jitter.py b/kornia/augmentation/_2d/intensity/color_jitter.pyindex 0c96d0189..91fe20be5 100644--- a/kornia/augmentation/_2d/intensity/color_jitter.py+++ b/kornia/augmentation/_2d/intensity/color_jitter.py@@ -45,11 +45,14 @@ class ColorJitter(IntensityAugmentationBase2D):contrast: The contrast factor to apply.saturation: The saturation factor to apply.hue: The hue factor to apply.- silence_instantiation_warning: if True, silence the warning at instantiation.same_on_batch: apply the same transformation across the batch.p: probability of applying the transformation.keepdim: whether to keep the output shape the same as input (True) or broadcast itto the batch form (False).+ order: a fixed application order, as indices into (brightness, contrast, saturation, hue); a subset+ applies only those. ``None`` (the default) draws a random order on every call. A fixed order makes+ the transform ``torch.compile`` fullgraph-safe. The parameter generator still draws an ``order``+ entry into ``_params``, and with a fixed order that entry is ignored, including on replay.Shape:- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`- Output: :math:`(B, C, H, W)`diff --git a/kornia/augmentation/_2d/intensity/gaussian_blur.py b/kornia/augmentation/_2d/intensity/gaussian_blur.pyindex 560820c4d..ae5c34a42 100644--- a/kornia/augmentation/_2d/intensity/gaussian_blur.py+++ b/kornia/augmentation/_2d/intensity/gaussian_blur.py@@ -43,7 +43,6 @@ class RandomGaussianBlur(IntensityAugmentationBase2D):p: probability of applying the transformation.keepdim: whether to keep the output shape the same as input (True) or broadcast itto the batch form (False).- silence_instantiation_warning: if True, silence the warning at instantiation.Shape:- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`diff --git a/tests/augmentation/test_args_docstrings.py b/tests/augmentation/test_args_docstrings.pynew file mode 100644index 000000000..84d9a8210--- /dev/null+++ b/tests/augmentation/test_args_docstrings.py@@ -0,0 +1,39 @@+# LICENSE HEADER MANAGED BY add-license-header+#+# Copyright 2018 Kornia Team+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++import inspect+import re++import pytest++import kornia.augmentation as K+++def _documented_args(cls):+ doc = inspect.getdoc(cls) or ""+ block = re.search(r"Args:\n(.*?)\n\s*(?:Shape|Returns|Examples?|\.\. note::|Note)", doc, re.S)+ assert block, f"{cls.__name__} has no Args block"+ return [match.group(1) for match in re.finditer(r"^\s{4}(\w+):", block.group(1), re.M)]++[email protected]("cls", [K.ColorJitter, K.ColorJiggle, K.RandomBrightness, K.RandomGaussianBlur])+def test_args_block_matches_the_constructor(cls):+ # kornia#4437: three classes documented a `silence_instantiation_warning` argument that does not+ # exist, and ColorJitter did not document its real `order` argument.+ signature = list(inspect.signature(cls.__init__).parameters)[1:]++ assert sorted(_documented_args(cls)) == sorted(signature)