kornia.testing#
The testing package contains testing-specific utilities.
- kornia.testing.KORNIA_CHECK(condition, msg=None)[source]#
Check any arbitrary boolean condition.
- Parameters:
- Raises:
Exception – if the confition is met.
- Return type:
Example
>>> x = torch.rand(2, 3, 3) >>> KORNIA_CHECK(x.shape[-2:] == (3, 3), "Invalid homography")
- kornia.testing.KORNIA_CHECK_DM_DESC(desc1, desc2, dm)[source]#
Check whether the provided descriptors match with a distance matrix.
- Parameters:
- Raises:
TypeException – if the descriptors shape do not match with the distance matrix.
Example
>>> desc1 = torch.rand(4) >>> desc2 = torch.rand(8) >>> dm = torch.rand(4, 8) >>> KORNIA_CHECK_DM_DESC(desc1, desc2, dm)
- kornia.testing.KORNIA_CHECK_IS_COLOR(x, msg=None)[source]#
Check whether an image tensor is a color images.
- Parameters:
- Raises:
TypeException – if all the input tensor has not a shape \((3,H,W)\).
Example
>>> img = torch.rand(2, 3, 4, 4) >>> KORNIA_CHECK_IS_COLOR(img, "Image is not color")
- kornia.testing.KORNIA_CHECK_IS_GRAY(x, msg=None)[source]#
Check whether an image tensor is grayscale.
- Parameters:
- Raises:
TypeException – if the tensor has not a shape \((1,H,W)\) or \((H,W)\).
Example
>>> img = torch.rand(2, 1, 4, 4) >>> KORNIA_CHECK_IS_GRAY(img, "Image is not grayscale")
- kornia.testing.KORNIA_CHECK_IS_TENSOR(x, msg=None)[source]#
Check the input variable is a Tensor.
- Parameters:
- Raises:
TypeException – if the input variable does not match with the expected.
Example
>>> x = torch.rand(2, 3, 3) >>> KORNIA_CHECK_IS_TENSOR(x, "Invalid tensor")
- kornia.testing.KORNIA_CHECK_LAF(laf)[source]#
Check whether a Local Affine Frame (laf) has a valid shape.
- Parameters:
laf (
Tensor
) – local affine frame tensor to evaluate.- Raises:
Exception – if the input laf does not have a shape \((B,N,2,3)\).
- Return type:
Example
>>> lafs = torch.rand(2, 10, 2, 3) >>> KORNIA_CHECK_LAF(lafs)
- kornia.testing.KORNIA_CHECK_SAME_DEVICE(x, y)[source]#
Check whether two tensor in the same device.
- Parameters:
- Raises:
TypeException – if the two tensors are not in the same device.
Example
>>> x1 = torch.rand(2, 3, 3) >>> x2 = torch.rand(1, 3, 1) >>> KORNIA_CHECK_SAME_DEVICE(x1, x2)
- kornia.testing.KORNIA_CHECK_SAME_DEVICES(tensors, msg=None)[source]#
Check whether a list provided tensors live in the same device.
- Parameters:
- Raises:
Exception – if all the tensors are not in the same device.
Example
>>> x1 = torch.rand(2, 3, 3) >>> x2 = torch.rand(1, 3, 1) >>> KORNIA_CHECK_SAME_DEVICES([x1, x2], "Tensors not in the same device")
- kornia.testing.KORNIA_CHECK_SHAPE(x, shape)[source]#
Check whether a tensor has a specified shape.
The shape can be specified with a implicit or explicit list of strings. The guard also check whether the variable is a type Tensor.
- Parameters:
- Raises:
Exception – if the input tensor is has not the expected shape.
- Return type:
Example
>>> x = torch.rand(2, 3, 4, 4) >>> KORNIA_CHECK_SHAPE(x, ["B","C", "H", "W"]) # implicit
>>> x = torch.rand(2, 3, 4, 4) >>> KORNIA_CHECK_SHAPE(x, ["2","3", "H", "W"]) # explicit
- kornia.testing.KORNIA_CHECK_TYPE(x, typ, msg=None)[source]#
Check the type of an aribratry variable.
- Parameters:
- Raises:
TypeException – if the input variable does not match with the expected.
Example
>>> KORNIA_CHECK_TYPE("foo", str, "Invalid string")
- kornia.testing.KORNIA_UNWRAP(maybe_obj, typ)[source]#
Unwraps an optional contained value that may or not be present.
- Parameters:
maybe_obj – the object to unwrap.
typ – expected type after unwrap.
- kornia.testing.create_eye_batch(batch_size, eye_size, device=None, dtype=None)[source]#
Create a batch of identity matrices of shape Bx3x3.