π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
params attribute private
dvd4207595c277792
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.pyindex 19410265c..48cb482d4 100644--- a/kornia/augmentation/augmentation.py+++ b/kornia/augmentation/augmentation.py@@ -91,16 +91,16 @@ class RandomHorizontalFlip(AugmentationBase):def __init__(self, p: float = 0.5, return_transform: bool = False) -> None:super(RandomHorizontalFlip, self).__init__(F.apply_hflip, return_transform)self.p: float = p- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def set_params(self, batch_size: int, p: float):- self.params = pg._random_prob_gen(batch_size, p)+ self._params = pg._random_prob_gen(batch_size, p)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignoreif params is None:batch_size = self.infer_batch_size(input)self.set_params(batch_size, self.p)- return super().forward(input, self.params)+ return super().forward(input, self._params)class RandomVerticalFlip(AugmentationBase):@@ -136,16 +136,16 @@ class RandomVerticalFlip(AugmentationBase):def __init__(self, p: float = 0.5, return_transform: bool = False) -> None:super(RandomVerticalFlip, self).__init__(F.apply_vflip, return_transform)self.p: float = p- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def set_params(self, batch_size: int, p: float):- self.params = pg._random_prob_gen(batch_size, p)+ self._params = pg._random_prob_gen(batch_size, p)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignoreif params is None:batch_size = self.infer_batch_size(input)self.set_params(batch_size, self.p)- return super().forward(input, self.params)+ return super().forward(input, self._params)class ColorJitter(AugmentationBase):@@ -172,7 +172,7 @@ class ColorJitter(AugmentationBase):self.saturation: FloatUnionType = saturationself.hue: FloatUnionType = hueself.return_transform: bool = return_transform- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def __repr__(self) -> str:repr = f"(brightness={self.brightness}, contrast={self.contrast}, saturation={self.saturation},\@@ -181,13 +181,13 @@ class ColorJitter(AugmentationBase):def set_params(self, batch_size: int, brightness: FloatUnionType = 0., contrast: FloatUnionType = 0.,saturation: FloatUnionType = 0., hue: FloatUnionType = 0.):- self.params = pg._random_color_jitter_gen(batch_size, brightness, contrast, saturation, hue)+ self._params = pg._random_color_jitter_gen(batch_size, brightness, contrast, saturation, hue)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignoreif params is None:batch_size = self.infer_batch_size(input)self.set_params(batch_size, self.brightness, self.contrast, self.saturation, self.hue)- return super().forward(input, self.params)+ return super().forward(input, self._params)class RandomGrayscale(AugmentationBase):@@ -203,20 +203,20 @@ class RandomGrayscale(AugmentationBase):def __init__(self, p: float = 0.5, return_transform: bool = False) -> None:super(RandomGrayscale, self).__init__(F.apply_grayscale, return_transform)self.p = p- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def __repr__(self) -> str:repr = f"(p={self.p}, return_transform={self.return_transform})"return self.__class__.__name__ + reprdef set_params(self, batch_size: int, p: float = .5):- self.params = pg._random_prob_gen(batch_size, p)+ self._params = pg._random_prob_gen(batch_size, p)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignoreif params is None:batch_size = self.infer_batch_size(input)self.set_params(batch_size, self.p)- return super().forward(input, self.params)+ return super().forward(input, self._params)class RandomRectangleErasing(nn.Module):@@ -270,7 +270,7 @@ class RandomPerspective(AugmentationBase):self.p: float = pself.distortion_scale: float = distortion_scaleself.return_transform: bool = return_transform- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def __repr__(self) -> str:repr = f"(distortion_scale={self.distortion_scale}, p={self.p}, return_transform={self.return_transform})"@@ -278,14 +278,14 @@ class RandomPerspective(AugmentationBase):def set_params(self, batch_size: int, height: int, width: int, p: float,distortion_scale: float):- self.params = pg._random_perspective_gen(batch_size, height, width, p, distortion_scale)+ self._params = pg._random_perspective_gen(batch_size, height, width, p, distortion_scale)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignoreif params is None:height, width = self.infer_image_shape(input)batch_size: int = self.infer_batch_size(input)self.set_params(batch_size, height, width, self.p, self.distortion_scale)- return super().forward(input, self.params)+ return super().forward(input, self._params)class RandomAffine(AugmentationBase):@@ -328,7 +328,7 @@ class RandomAffine(AugmentationBase):self.scale = scaleself.shear = shearself.return_transform = return_transform- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def set_params(self, batch_size: int,height: int,@@ -337,14 +337,14 @@ class RandomAffine(AugmentationBase):translate: Optional[TupleFloat] = None,scale: Optional[TupleFloat] = None,shear: Optional[UnionFloat] = None):- self.params = pg._random_affine_gen(batch_size, height, width, degrees, translate, scale, shear)+ self._params = pg._random_affine_gen(batch_size, height, width, degrees, translate, scale, shear)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignoreif params is None:height, width = self.infer_image_shape(input)batch_size: int = self.infer_batch_size(input)self.set_params(batch_size, height, width, self.degrees, self.translate, self.scale, self.shear)- return super().forward(input, self.params)+ return super().forward(input, self._params)class CenterCrop(AugmentationBase):@@ -410,14 +410,14 @@ class RandomRotation(AugmentationBase):def __init__(self, degrees: FloatUnionType = 45.0, return_transform: bool = False) -> None:super(RandomRotation, self).__init__(F.apply_rotation, return_transform)self.degrees = degrees- self.params: Dict[str, torch.Tensor] = {}+ self._params: Dict[str, torch.Tensor] = {}def __repr__(self) -> str:repr = f"(degrees={self.degrees}, return_transform={self.return_transform})"return self.__class__.__name__ + reprdef set_params(self, batch_size: int, degrees: FloatUnionType):- self.params = pg._random_rotation_gen(batch_size, degrees)+ self._params = pg._random_rotation_gen(batch_size, degrees)def forward(self, input: UnionType, params: Optional[Dict[str, torch.Tensor]] = None) -> UnionType: # type: ignore@@ -425,4 +425,4 @@ class RandomRotation(AugmentationBase):height, width = self.infer_image_shape(input)batch_size: int = self.infer_batch_size(input)self.set_params(batch_size, self.degrees)- return super().forward(input, self.params)+ return super().forward(input, self._params)diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.pyindex 802de454d..816ee1e27 100644--- a/test/augmentation/test_augmentation.py+++ b/test/augmentation/test_augmentation.py@@ -31,16 +31,19 @@ class TestRandomHorizontalFlip:input = torch.tensor([[0., 0., 0., 0.],[0., 0., 0., 0.],[0., 0., 1., 2.]]) # 3 x 4+input = input.to(device)expected = torch.tensor([[0., 0., 0., 0.],[0., 0., 0., 0.],[2., 1., 0., 0.]]) # 3 x 4+expected = expected.to(device)expected_transform = torch.tensor([[-1., 0., 4.],[0., 1., 0.],[0., 0., 1.]]) # 3 x 3+expected_transform = expected_transform.to(device)identity = torch.tensor([[1., 0., 0.],