Ge Zheng
commited on
Commit
·
a9589f3
1
Parent(s):
c62d838
add probability flag for hsv_augmentation and random_flip (#592)
Browse files- exps/example/yolox_voc/yolox_voc_s.py +15 -2
- yolox/data/data_augment.py +8 -5
- yolox/exp/yolox_base.py +10 -2
exps/example/yolox_voc/yolox_voc_s.py
CHANGED
@@ -15,6 +15,13 @@ class Exp(MyExp):
|
|
15 |
self.depth = 0.33
|
16 |
self.width = 0.50
|
17 |
self.warmup_epochs = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
|
19 |
|
20 |
def get_data_loader(self, batch_size, is_distributed, no_aug=False, cache_img=False):
|
@@ -38,7 +45,10 @@ class Exp(MyExp):
|
|
38 |
data_dir=os.path.join(get_yolox_datadir(), "VOCdevkit"),
|
39 |
image_sets=[('2007', 'trainval'), ('2012', 'trainval')],
|
40 |
img_size=self.input_size,
|
41 |
-
preproc=TrainTransform(
|
|
|
|
|
|
|
42 |
cache=cache_img,
|
43 |
)
|
44 |
|
@@ -46,7 +56,10 @@ class Exp(MyExp):
|
|
46 |
dataset,
|
47 |
mosaic=not no_aug,
|
48 |
img_size=self.input_size,
|
49 |
-
preproc=TrainTransform(
|
|
|
|
|
|
|
50 |
degrees=self.degrees,
|
51 |
translate=self.translate,
|
52 |
mosaic_scale=self.mosaic_scale,
|
|
|
15 |
self.depth = 0.33
|
16 |
self.width = 0.50
|
17 |
self.warmup_epochs = 1
|
18 |
+
|
19 |
+
# ---------- transform config ------------ #
|
20 |
+
self.mosaic_prob = 1.0
|
21 |
+
self.mixup_prob = 1.0
|
22 |
+
self.hsv_prob = 1.0
|
23 |
+
self.flip_prob = 0.5
|
24 |
+
|
25 |
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
|
26 |
|
27 |
def get_data_loader(self, batch_size, is_distributed, no_aug=False, cache_img=False):
|
|
|
45 |
data_dir=os.path.join(get_yolox_datadir(), "VOCdevkit"),
|
46 |
image_sets=[('2007', 'trainval'), ('2012', 'trainval')],
|
47 |
img_size=self.input_size,
|
48 |
+
preproc=TrainTransform(
|
49 |
+
max_labels=50,
|
50 |
+
flip_prob=self.flip_prob,
|
51 |
+
hsv_prob=self.hsv_prob),
|
52 |
cache=cache_img,
|
53 |
)
|
54 |
|
|
|
56 |
dataset,
|
57 |
mosaic=not no_aug,
|
58 |
img_size=self.input_size,
|
59 |
+
preproc=TrainTransform(
|
60 |
+
max_labels=120,
|
61 |
+
flip_prob=self.flip_prob,
|
62 |
+
hsv_prob=self.hsv_prob),
|
63 |
degrees=self.degrees,
|
64 |
translate=self.translate,
|
65 |
mosaic_scale=self.mosaic_scale,
|
yolox/data/data_augment.py
CHANGED
@@ -140,9 +140,9 @@ def random_perspective(
|
|
140 |
return img, targets
|
141 |
|
142 |
|
143 |
-
def _mirror(image, boxes):
|
144 |
_, width, _ = image.shape
|
145 |
-
if random.
|
146 |
image = image[:, ::-1]
|
147 |
boxes = boxes.copy()
|
148 |
boxes[:, 0::2] = width - boxes[:, 2::-2]
|
@@ -169,8 +169,10 @@ def preproc(img, input_size, swap=(2, 0, 1)):
|
|
169 |
|
170 |
|
171 |
class TrainTransform:
|
172 |
-
def __init__(self, max_labels=50):
|
173 |
self.max_labels = max_labels
|
|
|
|
|
174 |
|
175 |
def __call__(self, image, targets, input_dim):
|
176 |
boxes = targets[:, :4].copy()
|
@@ -188,8 +190,9 @@ class TrainTransform:
|
|
188 |
# bbox_o: [xyxy] to [c_x,c_y,w,h]
|
189 |
boxes_o = xyxy2cxcywh(boxes_o)
|
190 |
|
191 |
-
|
192 |
-
|
|
|
193 |
height, width, _ = image_t.shape
|
194 |
image_t, r_ = preproc(image_t, input_dim)
|
195 |
# boxes [xyxy] 2 [cx,cy,w,h]
|
|
|
140 |
return img, targets
|
141 |
|
142 |
|
143 |
+
def _mirror(image, boxes, prob=0.5):
|
144 |
_, width, _ = image.shape
|
145 |
+
if random.random() < prob:
|
146 |
image = image[:, ::-1]
|
147 |
boxes = boxes.copy()
|
148 |
boxes[:, 0::2] = width - boxes[:, 2::-2]
|
|
|
169 |
|
170 |
|
171 |
class TrainTransform:
|
172 |
+
def __init__(self, max_labels=50, flip_prob=0.5, hsv_prob=1.0):
|
173 |
self.max_labels = max_labels
|
174 |
+
self.flip_prob = flip_prob
|
175 |
+
self.hsv_prob = hsv_prob
|
176 |
|
177 |
def __call__(self, image, targets, input_dim):
|
178 |
boxes = targets[:, :4].copy()
|
|
|
190 |
# bbox_o: [xyxy] to [c_x,c_y,w,h]
|
191 |
boxes_o = xyxy2cxcywh(boxes_o)
|
192 |
|
193 |
+
if random.random() < self.hsv_prob:
|
194 |
+
augment_hsv(image)
|
195 |
+
image_t, boxes = _mirror(image, boxes, self.flip_prob)
|
196 |
height, width, _ = image_t.shape
|
197 |
image_t, r_ = preproc(image_t, input_dim)
|
198 |
# boxes [xyxy] 2 [cx,cy,w,h]
|
yolox/exp/yolox_base.py
CHANGED
@@ -38,6 +38,8 @@ class Exp(BaseExp):
|
|
38 |
# --------------- transform config ----------------- #
|
39 |
self.mosaic_prob = 1.0
|
40 |
self.mixup_prob = 1.0
|
|
|
|
|
41 |
self.degrees = 10.0
|
42 |
self.translate = 0.1
|
43 |
self.mosaic_scale = (0.1, 2)
|
@@ -110,7 +112,10 @@ class Exp(BaseExp):
|
|
110 |
data_dir=self.data_dir,
|
111 |
json_file=self.train_ann,
|
112 |
img_size=self.input_size,
|
113 |
-
preproc=TrainTransform(
|
|
|
|
|
|
|
114 |
cache=cache_img,
|
115 |
)
|
116 |
|
@@ -118,7 +123,10 @@ class Exp(BaseExp):
|
|
118 |
dataset,
|
119 |
mosaic=not no_aug,
|
120 |
img_size=self.input_size,
|
121 |
-
preproc=TrainTransform(
|
|
|
|
|
|
|
122 |
degrees=self.degrees,
|
123 |
translate=self.translate,
|
124 |
mosaic_scale=self.mosaic_scale,
|
|
|
38 |
# --------------- transform config ----------------- #
|
39 |
self.mosaic_prob = 1.0
|
40 |
self.mixup_prob = 1.0
|
41 |
+
self.hsv_prob = 1.0
|
42 |
+
self.flip_prob = 0.5
|
43 |
self.degrees = 10.0
|
44 |
self.translate = 0.1
|
45 |
self.mosaic_scale = (0.1, 2)
|
|
|
112 |
data_dir=self.data_dir,
|
113 |
json_file=self.train_ann,
|
114 |
img_size=self.input_size,
|
115 |
+
preproc=TrainTransform(
|
116 |
+
max_labels=50,
|
117 |
+
flip_prob=self.flip_prob,
|
118 |
+
hsv_prob=self.hsv_prob),
|
119 |
cache=cache_img,
|
120 |
)
|
121 |
|
|
|
123 |
dataset,
|
124 |
mosaic=not no_aug,
|
125 |
img_size=self.input_size,
|
126 |
+
preproc=TrainTransform(
|
127 |
+
max_labels=120,
|
128 |
+
flip_prob=self.flip_prob,
|
129 |
+
hsv_prob=self.hsv_prob),
|
130 |
degrees=self.degrees,
|
131 |
translate=self.translate,
|
132 |
mosaic_scale=self.mosaic_scale,
|