jianbin01 commited on
Commit
871109f
·
1 Parent(s): fe093af

fix hsv augment overflow error (#802)

Browse files
Files changed (1) hide show
  1. yolox/data/data_augment.py +3 -4
yolox/data/data_augment.py CHANGED
@@ -21,15 +21,14 @@ from yolox.utils import xyxy2cxcywh
21
  def augment_hsv(img, hgain=5, sgain=30, vgain=30):
22
  hsv_augs = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] # random gains
23
  hsv_augs *= np.random.randint(0, 2, 3) # random selection of h, s, v
24
- img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
25
- dtype = img.dtype # uint8
26
 
27
- hsv_augs = hsv_augs.astype(dtype)
28
  img_hsv[..., 0] = (img_hsv[..., 0] + hsv_augs[0]) % 180
29
  img_hsv[..., 1] = np.clip(img_hsv[..., 1] + hsv_augs[1], 0, 255)
30
  img_hsv[..., 2] = np.clip(img_hsv[..., 2] + hsv_augs[2], 0, 255)
31
 
32
- cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed
33
 
34
 
35
  def get_aug_params(value, center=0):
 
21
  def augment_hsv(img, hgain=5, sgain=30, vgain=30):
22
  hsv_augs = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] # random gains
23
  hsv_augs *= np.random.randint(0, 2, 3) # random selection of h, s, v
24
+ hsv_augs = hsv_augs.astype(np.int16)
25
+ img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV).astype(np.int16)
26
 
 
27
  img_hsv[..., 0] = (img_hsv[..., 0] + hsv_augs[0]) % 180
28
  img_hsv[..., 1] = np.clip(img_hsv[..., 1] + hsv_augs[1], 0, 255)
29
  img_hsv[..., 2] = np.clip(img_hsv[..., 2] + hsv_augs[2], 0, 255)
30
 
31
+ cv2.cvtColor(img_hsv.astype(img.dtype), cv2.COLOR_HSV2BGR, dst=img) # no return needed
32
 
33
 
34
  def get_aug_params(value, center=0):