Skip to content

Commit 2af997c

Browse files
authored
Update yolo_training.py
1 parent e85e015 commit 2af997c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

nets/yolo_training.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
import cv2
22
from random import shuffle
33
import numpy as np
44
import torch
@@ -349,15 +349,16 @@ def get_random_data(self, annotation_line, input_shape, jitter=.3, hue=.1, sat=1
349349
hue = rand(-hue, hue)
350350
sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat)
351351
val = rand(1, val) if rand()<.5 else 1/rand(1, val)
352-
x = rgb_to_hsv(np.array(image)/255.)
353-
x[..., 0] += hue
352+
x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV)
353+
x[..., 0] += hue*360
354354
x[..., 0][x[..., 0]>1] -= 1
355355
x[..., 0][x[..., 0]<0] += 1
356356
x[..., 1] *= sat
357357
x[..., 2] *= val
358-
x[x>1] = 1
358+
x[x[:,:, 0]>360, 0] = 360
359+
x[:, :, 1:][x[:, :, 1:]>1] = 1
359360
x[x<0] = 0
360-
image_data = hsv_to_rgb(x)*255 # numpy array, 0 to 1
361+
image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB)*255
361362

362363
# correct boxes
363364
box_data = np.zeros((len(box),5))
@@ -428,16 +429,17 @@ def get_random_data_with_Mosaic(self, annotation_line, input_shape, hue=.1, sat=
428429
hue = rand(-hue, hue)
429430
sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat)
430431
val = rand(1, val) if rand()<.5 else 1/rand(1, val)
431-
x = rgb_to_hsv(np.array(image)/255.)
432-
x[..., 0] += hue
432+
x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV)
433+
x[..., 0] += hue*360
433434
x[..., 0][x[..., 0]>1] -= 1
434435
x[..., 0][x[..., 0]<0] += 1
435436
x[..., 1] *= sat
436437
x[..., 2] *= val
437-
x[x>1] = 1
438+
x[x[:,:, 0]>360, 0] = 360
439+
x[:, :, 1:][x[:, :, 1:]>1] = 1
438440
x[x<0] = 0
439-
image = hsv_to_rgb(x)
440-
441+
image = cv2.cvtColor(x, cv2.COLOR_HSV2RGB) # numpy array, 0 to 1
442+
441443
image = Image.fromarray((image*255).astype(np.uint8))
442444
# 将图片进行放置,分别对应四张分割图片的位置
443445
dx = place_x[index]

0 commit comments

Comments
 (0)