π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix mypy
dvd4298994b20c462
diff --git a/kornia/augmentation/augmentations.py b/kornia/augmentation/augmentations.pyindex 1ec76e15e..d904acbad 100644--- a/kornia/augmentation/augmentations.py+++ b/kornia/augmentation/augmentations.py@@ -1,4 +1,4 @@-from typing import Tuple, Union+from typing import Tuple, Union, castimport torchimport torch.nn as nn@@ -49,18 +49,28 @@ class RandomHorizontalFlip(nn.Module):repr = f"(p={self.p}, return_transform={self.return_transform})"return self.__class__.__name__ + repr- def forward(self, input: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]) -> UnionType: # type: ignore+ def forward(self, input: UnionType) -> UnionType: # type: ignoreif isinstance(input, tuple):+ inp: torch.Tensor = input[0]+ prev_trans: torch.Tensor = input[1]+if self.return_transform:- img, trans_mat = random_hflip(input[0], self.p, self.return_transform)- return img, input[1] @ trans_mat++ out = random_hflip(inp, p=self.p, return_transform=True)+ img: torch.Tensor = out[0]+ trans_mat: torch.Tensor = out[1]++ return img, prev_trans @ trans_mat++ # https://mypy.readthedocs.io/en/latest/casts.html cast the return type to please mypy gods+ img = cast(torch.Tensor, random_hflip(inp, p=self.p, return_transform=False))# Transform image but pass along the previous transformation- return random_hflip(input[0], self.p, self.return_transform), input[1]+ return img, prev_trans- return random_hflip(input, self.p, self.return_transform)+ return random_hflip(input, p=self.p, return_transform=self.return_transform)def random_hflip(input: torch.Tensor, p: float = 0.5, return_transform: bool = False) -> UnionType:diff --git a/kornia/filters/filter.py b/kornia/filters/filter.pyindex f757c353f..99f4bff69 100644--- a/kornia/filters/filter.py+++ b/kornia/filters/filter.py@@ -29,7 +29,7 @@ def filter2D(input: torch.Tensor, kernel: torch.Tensor,input (torch.Tensor): the input tensor with shape of:math:`(B, C, H, W)`.kernel (torch.Tensor): the kernel to be convolved with the input- tensor. The kernel shape must be :math:`(B, kH, kW)`.+ tensor. The kernel shape must be :math:`(1, kH, kW)`.border_type (str): the padding mode to be applied before convolving.The expected modes are: ``'constant'``, ``'reflect'``,``'replicate'`` or ``'circular'``. Default: ``'reflect'``.@@ -56,7 +56,7 @@ def filter2D(input: torch.Tensor, kernel: torch.Tensor,.format(input.shape))if not len(kernel.shape) == 3:- raise ValueError("Invalid kernel shape, we expect BxHxW. Got: {}"+ raise ValueError("Invalid kernel shape, we expect 1xHxW. Got: {}".format(kernel.shape))borders_list: List[str] = ['constant', 'reflect', 'replicate', 'circular']