From e42f3adee17d86fc20dc89caf989ee05563ad4a2 Mon Sep 17 00:00:00 2001 From: jkbmrz Date: Fri, 20 Dec 2024 16:22:53 +0100 Subject: [PATCH] fix: normalization to prevent divison-by-zero --- depthai_nodes/ml/parsers/utils/denormalize.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/depthai_nodes/ml/parsers/utils/denormalize.py b/depthai_nodes/ml/parsers/utils/denormalize.py index 148cfa7c..5f25f3e4 100644 --- a/depthai_nodes/ml/parsers/utils/denormalize.py +++ b/depthai_nodes/ml/parsers/utils/denormalize.py @@ -13,7 +13,13 @@ def unnormalize_image(image, normalize=True): """ # Normalize the image tensor to the range [0, 1] if normalize: - image = (image - image.min()) / (image.max() - image.min()) + min_val = image.min() + max_val = image.max() + if max_val != min_val: + image = (image - min_val) / (max_val - min_val) + else: + # Handle the case where all values in the image are the same + image = image - min_val # Scale to [0, 255] and clip the values to be in the proper range image = image * 255.0