Skip to content
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
4 changes: 2 additions & 2 deletions utils/augmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions utils/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}'
Expand All @@ -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
Comment thread
glenn-jocher marked this conversation as resolved.

def cache_images_to_disk(self, i):
# Saves an image as an *.npy file for faster loading
Expand Down