π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix typing
dvd42f157f1c45a45
diff --git a/kornia/augmentation/augmentations.py b/kornia/augmentation/augmentations.pyindex ce118ce46..413701d81 100644--- a/kornia/augmentation/augmentations.py+++ b/kornia/augmentation/augmentations.py@@ -1,6 +1,7 @@import torchimport torch.nn as nn-from kornia.geometry.transform import flips+from typing import Tuple+from kornia.geometry.transform.flips import hflipclass RandomHorizontalFlip(nn.Module):@@ -20,11 +21,11 @@ class RandomHorizontalFlip(nn.Module):repr = "(p={0})".format(self.p)return self.__class__.__name__ + repr- def forward(self, input: torch.Tensor) -> torch.Tensor: # type: ignore+ def forward(self, input: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: # type: ignorereturn random_hflip(input, self.p)-def random_hflip(input, p=0.5):+def random_hflip(input, p=0.5) -> Tuple[torch.Tensor, torch.Tensor]:r"""Horizontally flip a tensor image or a batch of tensor images randomly with a given probability.Input should be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.@@ -49,13 +50,13 @@ def random_hflip(input, p=0.5):probs: torch.Tensor = torch.empty(input.shape[0], device=device).uniform_(0, 1)else:input = input.unsqueeze(0)- probs: torch.Tensor = torch.empty(1, device=device).uniform_(0, 1)+ probs = torch.empty(1, device=device).uniform_(0, 1)to_flip: torch.Tensor = probs < pif input[to_flip].nelement() != 0:- flipped: torch.Tensor = flips.hflip(input[to_flip])+ flipped: torch.Tensor = hflip(input[to_flip])trans_mat: torch.Tensor = torch.zeros((3, 3))trans_mat[0][0] = -1trans_mat[1][1] = 1diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.pyindex cf93e2058..8417506e8 100644--- a/test/augmentation/test_augmentation.py+++ b/test/augmentation/test_augmentation.py@@ -104,9 +104,7 @@ class TestRandomHorizontalFlip:def test_gradcheck(self):- input = torch.tensor([[0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]]).double() # 3 x 3+ input = torch.rand((3, 3)).double() # 3 x 3input = utils.tensor_to_gradcheck_var(input) # to var