diff --git a/utils/augmentations.py b/utils/augmentations.py index 3f764c06ae3b..cd3f8139ac9f 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -48,7 +48,7 @@ def augment_hsv(im, hgain=0.5, sgain=0.5, vgain=0.5): # HSV color-space augmentation if hgain or sgain or vgain: r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1 # random gains - hue, sat, val = cv2.split(cv2.cvtColor(im, cv2.COLOR_BGR2HSV)) + hue, sat, val = cv2.split(cv2.cvtColor(im, cv2.COLOR_RGB2HSV)) dtype = im.dtype # uint8 x = np.arange(0, 256, dtype=r.dtype) @@ -57,7 +57,7 @@ def augment_hsv(im, hgain=0.5, sgain=0.5, vgain=0.5): lut_val = np.clip(x * r[2], 0, 255).astype(dtype) im_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))) - cv2.cvtColor(im_hsv, cv2.COLOR_HSV2BGR, dst=im) # no return needed + cv2.cvtColor(im_hsv, cv2.COLOR_HSV2RGB, dst=im) # no return needed def hist_equalize(im, clahe=True, bgr=False): diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 9ccfe2545d75..796183558da4 100755 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -660,7 +660,7 @@ def __getitem__(self, index): labels_out[:, 1:] = torch.from_numpy(labels) # Convert - img = img.transpose((2, 0, 1))[::-1] # HWC to CHW, BGR to RGB + img = img.transpose((2, 0, 1)) # HWC to CHW img = np.ascontiguousarray(img) return torch.from_numpy(img), labels_out, self.im_files[index], shapes @@ -670,7 +670,7 @@ def load_image(self, i): im, f, fn = self.ims[i], self.im_files[i], self.npy_files[i], if im is None: # not cached in RAM if fn.exists(): # load npy - im = np.load(fn) + im = np.load(fn) # BGR else: # read image im = cv2.imread(f) # BGR assert im is not None, f'Image Not Found {f}' @@ -679,8 +679,8 @@ def load_image(self, i): if r != 1: # if sizes are not equal interp = cv2.INTER_LINEAR if (self.augment or r > 1) else cv2.INTER_AREA im = cv2.resize(im, (int(w0 * r), int(h0 * r)), interpolation=interp) - return im, (h0, w0), im.shape[:2] # im, hw_original, hw_resized - return self.ims[i], self.im_hw0[i], self.im_hw[i] # im, hw_original, hw_resized + return im[..., ::-1], (h0, w0), im.shape[:2] # im RGB, hw_original, hw_resized + return self.ims[i], self.im_hw0[i], self.im_hw[i] # im RGB, hw_original, hw_resized def cache_images_to_disk(self, i): # Saves an image as an *.npy file for faster loading