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

Revert "Fix BGR->RGB Bug in albumentations #8641" #8726

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions utils/augmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ def __init__(self):
def __call__(self, im, labels, p=1.0):
if self.transform and random.random() < p:
new = self.transform(image=im[..., ::-1], bboxes=labels[:, 1:], class_labels=labels[:, 0]) # transformed
im = new['image'][..., ::-1] # RGB to BGR
labels = np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])])
im, labels = new['image'], np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])])
return im, labels


def augment_hsv(im, hgain=0.5, sgain=0.5, vgain=0.5):
# HSV color-space augmentation
# HSV color-space augmentation, im is RGB
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)
Expand All @@ -58,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):
Expand Down
4 changes: 2 additions & 2 deletions utils/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def __getitem__(self, index):

if self.augment:
# Albumentations
img, labels = self.albumentations(img, labels)
img, labels = self.albumentations(img[..., ::-1], labels)
nl = len(labels) # update after albumentations

# HSV color-space
Expand All @@ -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, BGR to RGB
img = np.ascontiguousarray(img)

return torch.from_numpy(img), labels_out, self.im_files[index], shapes
Expand Down