π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Codebase clean
Jian Sa5c1731ecde0
diff --git a/kornia/augmentation/__init__.py b/kornia/augmentation/__init__.pyindex 0f42d4a00..de207ed21 100644--- a/kornia/augmentation/__init__.py+++ b/kornia/augmentation/__init__.py@@ -1 +1,10 @@from .augmentation import *+++__all__ = [+ "RandomHorizontalFlip",+ "RandomVerticalFlip",+ "RandomRectangleErasing",+ "RandomGrayscale",+ "ColorJitter",+]\ No newline at end of filediff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.pyindex 24aaa54e9..cbe3d47c8 100644--- a/kornia/augmentation/augmentation.py+++ b/kornia/augmentation/augmentation.py@@ -7,14 +7,6 @@ from . import functional as Ffrom . import param_gen as pg-__all__ = [- "RandomHorizontalFlip",- "RandomVerticalFlip",- "RandomRectangleErasing",- "RandomGrayscale",- "ColorJitter",-]-UnionType = Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]FloatUnionType = Union[torch.Tensor, float, Tuple[float, float], List[float]]diff --git a/kornia/augmentation/erasing.py b/kornia/augmentation/erasing.pyindex 4ed622171..ddaecb3c5 100644--- a/kornia/augmentation/erasing.py+++ b/kornia/augmentation/erasing.py@@ -5,41 +5,6 @@ import torch.nn as nnimport torch.distributions as tdist-'''class RandomRectangleErasing(nn.Module):- r"""- Erases a random selected rectangle for each image in the batch, putting the value to zero.- The rectangle will have an area equal to the original image area multiplied by a value uniformly- sampled between the range [erase_scale_range[0], erase_scale_range[1]) and an aspect ratio sampled- between [aspect_ratio_range[0], aspect_ratio_range[1])-- Args:- erase_scale_range (Tuple[float, float]): range of proportion of erased area against input image.- aspect_ratio_range (Tuple[float, float]): range of aspect ratio of erased area.-- Examples:- >>> inputs = torch.ones(1, 1, 3, 3)- >>> rec_er = kornia.augmentation.RandomRectangleErasing((.4, .8), (.3, 1/.3))- >>> rec_er(inputs)- tensor([[[[1., 0., 0.],- [1., 0., 0.],- [1., 0., 0.]]]])- """-- def __init__(- self, erase_scale_range: Tuple[float, float], aspect_ratio_range: Tuple[float, float]- ) -> None:- super(RandomRectangleErasing, self).__init__()- self.erase_scale_range: Tuple[float, float] = erase_scale_range- self.aspect_ratio_range: Tuple[float, float] = aspect_ratio_range-- def forward(self, images: torch.Tensor) -> torch.Tensor: # type: ignore- return random_rectangle_erase(- images,- self.erase_scale_range,- self.aspect_ratio_range- )'''--def get_random_rectangles_params(params_shape, images_height, images_width, erase_scale_range, aspect_ratio_range):@@ -106,42 +71,3 @@ def erase_rectangles(images, rectangle_params):mask = draw_rectangles(images.size(), rectangle_params, device)mask = 1. - maskreturn images * mask---'''def random_rectangle_erase(- images: torch.Tensor,- erase_scale_range: Tuple[float, float],- aspect_ratio_range: Tuple[float, float]-) -> torch.Tensor:- r"""- Function that erases a random selected rectangle for each image in the batch, putting- the value to zero.- The rectangle will have an area equal to the original image area multiplied by a value uniformly- sampled between the range [erase_scale_range[0], erase_scale_range[1]) and an aspect ratio sampled- between [aspect_ratio_range[0], aspect_ratio_range[1])-- Args:- images (torch.Tensor): input images.- erase_scale_range (Tuple[float, float]): range of proportion of erased area against input image.- aspect_ratio_range (Tuple[float, float]): range of aspect ratio of erased area.- """- if not (isinstance(erase_scale_range[0], float) and- isinstance(erase_scale_range[1], float) and- erase_scale_range[0] > 0. and erase_scale_range[1] > 0.):- raise TypeError(- f"'erase_scale_range' must be a Tuple[float, float] with positive values"- )- if not (isinstance(aspect_ratio_range[0], float) and- isinstance(aspect_ratio_range[1], float) and- aspect_ratio_range[0] > 0. and aspect_ratio_range[1] > 0.):- raise TypeError(- f"'aspect_ratio_range' must be a Tuple[float, float] with positive values"- )-- images_size = images.size()- b, _, h, w = images_size- rect_params = get_random_rectangles_params(- (b, ), h, w, erase_scale_range, aspect_ratio_range- )- images = erase_rectangles(images, rect_params)- return images'''diff --git a/kornia/augmentation/functional.py b/kornia/augmentation/functional.pyindex c5edf1ec3..1a0f45103 100644--- a/kornia/augmentation/functional.py+++ b/kornia/augmentation/functional.py@@ -107,9 +107,6 @@ def apply_hflip(input: torch.Tensor, params: Dict[str, torch.Tensor], return_tradevice: torch.device = input.devicedtype: torch.dtype = input.dtype- input = input.unsqueeze(0)- input = input.view((-1, (*input.shape[-3:])))-flipped: torch.Tensor = input.clone()to_flip = params['batch_prob'].to(device)diff --git a/kornia/color/hsv.py b/kornia/color/hsv.pyindex f42b5b06c..a3fa69540 100644--- a/kornia/color/hsv.py+++ b/kornia/color/hsv.py@@ -60,9 +60,10 @@ def hsv_to_rgb(image: torch.Tensor) -> torch.Tensor:hi: torch.Tensor = torch.floor(h * 6) % 6f: torch.Tensor = ((h * 6) % 6) - hi- p: torch.Tensor = v * (torch.tensor(1.).to(image.device) - s)- q: torch.Tensor = v * (torch.tensor(1.).to(image.device) - f * s)- t: torch.Tensor = v * (torch.tensor(1.).to(image.device) - (torch.tensor(1.).to(image.device) - f) * s)+ one: torch.Tensor = torch.tensor(1.).to(image.device)+ p: torch.Tensor = v * (one - s)+ q: torch.Tensor = v * (one - f * s)+ t: torch.Tensor = v * (one - (one - f) * s)out: torch.Tensor = torch.stack([hi, hi, hi], dim=-3)