Commit
•
5a1ef32
1
Parent(s):
5e077bf
Add random interpolation method augmentation (#6826)
Browse files* add random_interpolation option to make model robust to interpolation methods
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix precommit error
* Update augmentations.py
* Update augmentations.py
* Update augmentations.py
* Update datasets.py
* Update datasets.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>
- utils/datasets.py +3 -2
utils/datasets.py
CHANGED
@@ -397,6 +397,7 @@ def img2label_paths(img_paths):
|
|
397 |
class LoadImagesAndLabels(Dataset):
|
398 |
# YOLOv5 train_loader/val_loader, loads images and labels for training and validation
|
399 |
cache_version = 0.6 # dataset labels *.cache version
|
|
|
400 |
|
401 |
def __init__(self,
|
402 |
path,
|
@@ -665,8 +666,8 @@ class LoadImagesAndLabels(Dataset):
|
|
665 |
h0, w0 = im.shape[:2] # orig hw
|
666 |
r = self.img_size / max(h0, w0) # ratio
|
667 |
if r != 1: # if sizes are not equal
|
668 |
-
|
669 |
-
|
670 |
return im, (h0, w0), im.shape[:2] # im, hw_original, hw_resized
|
671 |
else:
|
672 |
return self.ims[i], self.im_hw0[i], self.im_hw[i] # im, hw_original, hw_resized
|
|
|
397 |
class LoadImagesAndLabels(Dataset):
|
398 |
# YOLOv5 train_loader/val_loader, loads images and labels for training and validation
|
399 |
cache_version = 0.6 # dataset labels *.cache version
|
400 |
+
rand_interp_methods = [cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4]
|
401 |
|
402 |
def __init__(self,
|
403 |
path,
|
|
|
666 |
h0, w0 = im.shape[:2] # orig hw
|
667 |
r = self.img_size / max(h0, w0) # ratio
|
668 |
if r != 1: # if sizes are not equal
|
669 |
+
interp = cv2.INTER_LINEAR if self.augment else cv2.INTER_AREA # random.choice(self.rand_interp_methods)
|
670 |
+
im = cv2.resize(im, (int(w0 * r), int(h0 * r)), interpolation=interp)
|
671 |
return im, (h0, w0), im.shape[:2] # im, hw_original, hw_resized
|
672 |
else:
|
673 |
return self.ims[i], self.im_hw0[i], self.im_hw[i] # im, hw_original, hw_resized
|