Skip to content

Commit

Permalink
Add random interpolation method augmentation (ultralytics#6826)
Browse files Browse the repository at this point in the history
* 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 <glenn.jocher@ultralytics.com>
  • Loading branch information
3 people authored and tdhooghe committed Jun 10, 2022
1 parent 97f1995 commit 6299397
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def img2label_paths(img_paths):
class LoadImagesAndLabels(Dataset):
# YOLOv5 train_loader/val_loader, loads images and labels for training and validation
cache_version = 0.6 # dataset labels *.cache version
rand_interp_methods = [cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4]

def __init__(self,
path,
Expand Down Expand Up @@ -666,8 +667,8 @@ def load_image(self, i):
h0, w0 = im.shape[:2] # orig hw
r = self.img_size / max(h0, w0) # ratio
if r != 1: # if sizes are not equal
im = cv2.resize(im, (int(w0 * r), int(h0 * r)),
interpolation=cv2.INTER_LINEAR if (self.augment or r > 1) else cv2.INTER_AREA)
interp = cv2.INTER_LINEAR if self.augment else cv2.INTER_AREA # random.choice(self.rand_interp_methods)
im = cv2.resize(im, (int(w0 * r), int(h0 * r)), interpolation=interp)
return im, (h0, w0), im.shape[:2] # im, hw_original, hw_resized
else:
return self.ims[i], self.im_hw0[i], self.im_hw[i] # im, hw_original, hw_resized
Expand Down

0 comments on commit 6299397

Please sign in to comment.