π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Accelerate augmentations (#708)
FGerib7a6f76822c3
diff --git a/kornia/color/hsv.py b/kornia/color/hsv.pyindex a5ca619ee..5cdaf2be7 100644--- a/kornia/color/hsv.py+++ b/kornia/color/hsv.py@@ -65,14 +65,14 @@ def hsv_to_rgb(image: torch.Tensor) -> torch.Tensor: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)-- out[out == 0] = torch.stack((v, t, p), dim=-3)[out == 0]- out[out == 1] = torch.stack((q, v, p), dim=-3)[out == 1]- out[out == 2] = torch.stack((p, v, t), dim=-3)[out == 2]- out[out == 3] = torch.stack((p, q, v), dim=-3)[out == 3]- out[out == 4] = torch.stack((t, p, v), dim=-3)[out == 4]- out[out == 5] = torch.stack((v, p, q), dim=-3)[out == 5]+ hi = hi.long()+ indices: torch.Tensor = torch.stack([hi, hi + 6, hi + 12], dim=-3)+ out = torch.stack((+ v, q, p, p, t, v,+ t, v, v, q, p, p,+ p, p, t, v, v, q,+ ), dim=-3)+ out = torch.gather(out, -3, indices)return out@@ -127,35 +127,29 @@ def rgb_to_hsv(image: torch.Tensor) -> torch.Tensor:raise ValueError("Input size must have a shape of (*, 3, H, W). Got {}".format(image.shape))- r: torch.Tensor = image[..., 0, :, :]- g: torch.Tensor = image[..., 1, :, :]- b: torch.Tensor = image[..., 2, :, :]-- maxc: torch.Tensor = image.max(-3)[0]+ maxc, max_indices = image.max(-3)minc: torch.Tensor = image.min(-3)[0]v: torch.Tensor = maxc # brightnessdeltac: torch.Tensor = maxc - minc- s: torch.Tensor = deltac / v-- s[torch.isnan(s)] = 0.+ s: torch.Tensor = deltac / (v + 1e-31)# avoid division by zerodeltac = torch.where(deltac == 0, torch.ones_like(deltac), deltac)- rc: torch.Tensor = (maxc - r) / deltac- gc: torch.Tensor = (maxc - g) / deltac- bc: torch.Tensor = (maxc - b) / deltac+ rc, gc, bc = torch.unbind(maxc.unsqueeze(-3) - image, dim=-3)- maxg: torch.Tensor = g == maxc- maxr: torch.Tensor = r == maxc+ h = torch.stack([+ bc - gc,+ 2.0 * deltac + rc - bc,+ 4.0 * deltac + gc - rc,+ ], dim=-3)- h: torch.Tensor = 4.0 + gc - rc- h[maxg] = 2.0 + rc[maxg] - bc[maxg]- h[maxr] = bc[maxr] - gc[maxr]- h[minc == maxc] = 0.0+ h = torch.gather(h, dim=-3, index=max_indices[..., None, :, :])+ h = h.squeeze(-3)+ h = h / deltach = (h / 6.0) % 1.0diff --git a/kornia/geometry/transform/flips.py b/kornia/geometry/transform/flips.pyindex 52249c2ac..d3e295f96 100644--- a/kornia/geometry/transform/flips.py+++ b/kornia/geometry/transform/flips.py@@ -123,8 +123,8 @@ def hflip(input: torch.Tensor) -> torch.Tensor:torch.Tensor: The horizontally flipped image tensor"""-- return torch.flip(input, [-1])+ w = input.shape[-1]+ return input[..., torch.arange(w - 1, -1, -1)]def vflip(input: torch.Tensor) -> torch.Tensor:@@ -139,4 +139,5 @@ def vflip(input: torch.Tensor) -> torch.Tensor:"""- return torch.flip(input, [-2])+ h = input.shape[-2]+ return input[..., torch.arange(h - 1, -1, -1), :]