From fde880d9b9359807ef2536d7351354d4e57e4e27 Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Wed, 5 Mar 2025 01:38:49 +0800 Subject: [PATCH] `ultralytics 8.3.83` Revert saturation and value augmentation to relative shift (#19515) Signed-off-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Signed-off-by: Glenn Jocher Co-authored-by: Laughing-q <1185102784@qq.com> Co-authored-by: Glenn Jocher --- ultralytics/__init__.py | 2 +- ultralytics/data/augment.py | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index dc200d5e..093c4aa5 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license -__version__ = "8.3.82" +__version__ = "8.3.83" import os diff --git a/ultralytics/data/augment.py b/ultralytics/data/augment.py index 5253da52..16339628 100644 --- a/ultralytics/data/augment.py +++ b/ultralytics/data/augment.py @@ -1368,20 +1368,13 @@ class RandomHSV: img = labels["img"] dtype = img.dtype # uint8 - # Original implementation (bug) from ultralytics<=8.3.78 - # r = np.random.uniform(-1, 1, 3) * [self.hgain, self.sgain, self.vgain] + 1 # random gains - # x = np.arange(0, 256, dtype=r.dtype) - # lut_hue = ((x * r[0]) % 180).astype(dtype) - # lut_sat = np.clip(x * r[1], 0, 255).astype(dtype) - # lut_val = np.clip(x * r[2], 0, 255).astype(dtype) - - # Fixed implementation in https://github.com/ultralytics/ultralytics/pull/19311 - r = np.random.uniform(-1, 1, 3) * (self.hgain, self.sgain, self.vgain) * (180, 255, 255) # random gains + r = np.random.uniform(-1, 1, 3) * [self.hgain, self.sgain, self.vgain] # random gains x = np.arange(0, 256, dtype=r.dtype) - lut_hue = ((x + r[0]) % 180).astype(dtype) - lut_sat = np.clip(x + r[1], 0, 255).astype(dtype) - lut_val = np.clip(x + r[2], 0, 255).astype(dtype) - lut_sat[0] = 0 # prevent pure white changing color + # lut_hue = ((x * (r[0] + 1)) % 180).astype(dtype) # original hue implementation from ultralytics<=8.3.78 + lut_hue = ((x + r[0] * 180) % 180).astype(dtype) + lut_sat = np.clip(x * (r[1] + 1), 0, 255).astype(dtype) + lut_val = np.clip(x * (r[2] + 1), 0, 255).astype(dtype) + lut_sat[0] = 0 # prevent pure white changing color, introduced in 8.3.79 hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV)) im_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val)))