Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: normalization to prevent divison-by-zero #155

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion depthai_nodes/ml/parsers/utils/denormalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading