π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Add warning for rgb_to_gray non-float images (#1012)
Dmytro Mishkin84d37a4fb3e5
diff --git a/kornia/color/gray.py b/kornia/color/gray.pyindex 8072666f1..b9ebddfd3 100644--- a/kornia/color/gray.py+++ b/kornia/color/gray.py@@ -1,5 +1,6 @@import torchimport torch.nn as nn+import warningsfrom kornia.color.rgb import bgr_to_rgb@@ -40,7 +41,8 @@ def rgb_to_grayscale(image: torch.Tensor,r: torch.Tensor = image[..., 0:1, :, :]g: torch.Tensor = image[..., 1:2, :, :]b: torch.Tensor = image[..., 2:3, :, :]-+ if image.dtype not in [torch.float16, torch.float32, torch.float64]:+ warnings.warn("Input image is not of float dtype. Got {}".format(image.dtype))w_tmp: torch.Tensor = rgb_weights.to(image.device, image.dtype)gray: torch.Tensor = w_tmp[..., 0] * r + w_tmp[..., 1] * g + w_tmp[..., 2] * breturn gray