JoshSong glenn-jocher commited on
Commit
5f7d39f
1 Parent(s): f7bc685

Cleanup load_image() (#2871)

Browse files

* don't resize up in load_image if augmenting

* cleanup

Co-authored-by: Glenn Jocher <[email protected]>

Files changed (1) hide show
  1. utils/datasets.py +4 -4
utils/datasets.py CHANGED
@@ -634,10 +634,10 @@ def load_image(self, index):
634
  img = cv2.imread(path) # BGR
635
  assert img is not None, 'Image Not Found ' + path
636
  h0, w0 = img.shape[:2] # orig hw
637
- r = self.img_size / max(h0, w0) # resize image to img_size
638
- if r != 1: # always resize down, only resize up if training with augmentation
639
- interp = cv2.INTER_AREA if r < 1 and not self.augment else cv2.INTER_LINEAR
640
- img = cv2.resize(img, (int(w0 * r), int(h0 * r)), interpolation=interp)
641
  return img, (h0, w0), img.shape[:2] # img, hw_original, hw_resized
642
  else:
643
  return self.imgs[index], self.img_hw0[index], self.img_hw[index] # img, hw_original, hw_resized
 
634
  img = cv2.imread(path) # BGR
635
  assert img is not None, 'Image Not Found ' + path
636
  h0, w0 = img.shape[:2] # orig hw
637
+ r = self.img_size / max(h0, w0) # ratio
638
+ if r != 1: # if sizes are not equal
639
+ img = cv2.resize(img, (int(w0 * r), int(h0 * r)),
640
+ interpolation=cv2.INTER_AREA if r < 1 and not self.augment else cv2.INTER_LINEAR)
641
  return img, (h0, w0), img.shape[:2] # img, hw_original, hw_resized
642
  else:
643
  return self.imgs[index], self.img_hw0[index], self.img_hw[index] # img, hw_original, hw_resized