Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Bug fixed (#475)

shijianjian6560af4a3ddc
diff --git a/kornia/color/hls.py b/kornia/color/hls.py
index c9a4a6153..5417c1b23 100644
--- a/kornia/color/hls.py
+++ b/kornia/color/hls.py
@@ -58,7 +58,7 @@ def hls_to_rgb(image: torch.Tensor) -> torch.Tensor:
raise ValueError("Input size must have a shape of (*, 3, H, W). Got {}"
.format(image.shape))
- h: torch.Tensor = image[..., 0, :, :] * 360 / (2 * pi)
+ h: torch.Tensor = image[..., 0, :, :] * 360 / (2 * pi.to(image.device))
l: torch.Tensor = image[..., 1, :, :]
s: torch.Tensor = image[..., 2, :, :]
@@ -154,7 +154,7 @@ def rgb_to_hls(image: torch.Tensor) -> torch.Tensor:
hi[imax == 1] = (((b - r) / deltac) + 2)[imax == 1]
hi[imax == 2] = (((r - g) / deltac) + 4)[imax == 2]
- h: torch.Tensor = 2. * pi * (60. * hi) / 360. # hue [0, 2*pi]
+ h: torch.Tensor = 2. * pi.to(image.device) * (60. * hi) / 360. # hue [0, 2*pi]
image_hls: torch.Tensor = torch.stack([h, l, s], dim=-3)
diff --git a/kornia/color/hsv.py b/kornia/color/hsv.py
index a3fa69540..97e45d480 100644
--- a/kornia/color/hsv.py
+++ b/kornia/color/hsv.py
@@ -54,7 +54,7 @@ def hsv_to_rgb(image: torch.Tensor) -> torch.Tensor:
raise ValueError("Input size must have a shape of (*, 3, H, W). Got {}"
.format(image.shape))
- h: torch.Tensor = image[..., 0, :, :] / (2 * pi)
+ h: torch.Tensor = image[..., 0, :, :] / (2 * pi.to(image.device))
s: torch.Tensor = image[..., 1, :, :]
v: torch.Tensor = image[..., 2, :, :]
@@ -159,5 +159,5 @@ def rgb_to_hsv(image: torch.Tensor) -> torch.Tensor:
h = (h / 6.0) % 1.0
- h = 2 * pi * h
+ h = 2 * pi.to(image.device) * h
return torch.stack([h, s, v], dim=-3)
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index e0d49473f..f1abfd727 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -387,11 +387,12 @@ def get_rotation_matrix2d(
# create output tensor
batch_size: int = center.shape[0]
+ one = torch.tensor(1.).to(center.device)
M: torch.Tensor = torch.zeros(
batch_size, 2, 3, device=center.device, dtype=center.dtype)
M[..., 0:2, 0:2] = scaled_rotation
- M[..., 0, 2] = (torch.tensor(1.) - alpha) * x - beta * y
- M[..., 1, 2] = beta * x + (torch.tensor(1.) - alpha) * y
+ M[..., 0, 2] = (one - alpha) * x - beta * y
+ M[..., 1, 2] = beta * x + (one - alpha) * y
return M