diff --git a/fluid/PaddleCV/yolov3/box_utils.py b/fluid/PaddleCV/yolov3/box_utils.py index 7dbf513272c9f489233a0106b5b6e84187cdb9d8..d6abe29cc6d483d72c50a8e96307a6fefd2ebab4 100644 --- a/fluid/PaddleCV/yolov3/box_utils.py +++ b/fluid/PaddleCV/yolov3/box_utils.py @@ -138,6 +138,8 @@ def rescale_box_in_input_image(boxes, im_shape, input_size): boxes[:, 2] *= fx boxes[:, 3] *= fy boxes[boxes<0] = 0 + boxes[:, 2][boxes[:, 2] > (w - 1)] = w - 1 + boxes[:, 3][boxes[:, 3] > (h - 1)] = h - 1 return boxes def box_crop(boxes, labels, scores, crop, img_shape): @@ -149,15 +151,16 @@ def box_crop(boxes, labels, scores, crop, img_shape): boxes[:, 1], boxes[:, 3] = (boxes[:, 1] - boxes[:, 3] / 2) * im_h, (boxes[:, 1] + boxes[:, 3] / 2) * im_h crop_box = np.array([x, y, x + w, y + h]) - centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 - mask = np.logical_and(crop_box[:2] <= centers, centers <= crop_box[2:]).all(axis=1) + # centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 + # mask = np.logical_and(crop_box[:2] <= centers, centers <= crop_box[2:]).all(axis=1) boxes[:, :2] = np.maximum(boxes[:, :2], crop_box[:2]) boxes[:, 2:] = np.minimum(boxes[:, 2:], crop_box[2:]) boxes[:, :2] -= crop_box[:2] boxes[:, 2:] -= crop_box[:2] - mask = np.logical_and(mask, (boxes[:, :2] < boxes[:, 2:]).all(axis=1)) + # mask = np.logical_and(mask, (boxes[:, :2] < boxes[:, 2:]).all(axis=1)) + mask = (boxes[:, :2] < boxes[:, 2:]).all(axis=1) boxes = boxes * np.expand_dims(mask.astype('float32'), axis=1) labels = labels * mask.astype('float32') scores = scores * mask.astype('float32') diff --git a/fluid/PaddleCV/yolov3/image_utils.py b/fluid/PaddleCV/yolov3/image_utils.py index e16a6afbe355c438c8bc6db7b3a847b5b2ab70ba..a24a056fb41f6b4a6dfccd15352bf0f2f4c10923 100644 --- a/fluid/PaddleCV/yolov3/image_utils.py +++ b/fluid/PaddleCV/yolov3/image_utils.py @@ -121,7 +121,7 @@ def random_interp(img, size, interp=None): img = cv2.resize(img, None, None, fx=im_scale_x, fy=im_scale_y, interpolation=interp) return img -def random_expand(img, gtboxes, max_ratio=2., fill=None, keep_ratio=True, thresh=0.5): +def random_expand(img, gtboxes, max_ratio=4., fill=None, keep_ratio=True, thresh=0.5): if random.random() > thresh: return img, gtboxes diff --git a/fluid/PaddleCV/yolov3/learning_rate.py b/fluid/PaddleCV/yolov3/learning_rate.py index bb76699fb3b79327307b5971152406d06f8d08d1..6a44cfe8d8e0dcd9faf5d439f5501318a8937850 100644 --- a/fluid/PaddleCV/yolov3/learning_rate.py +++ b/fluid/PaddleCV/yolov3/learning_rate.py @@ -23,7 +23,7 @@ from paddle.fluid.layers import control_flow def exponential_with_warmup_decay(learning_rate, boundaries, values, warmup_iter, warmup_factor, start_step): - global_step = lr_scheduler._decay_step_counter() + start_step + global_step = lr_scheduler._decay_step_counter() lr = fluid.layers.create_global_var( shape=[1], diff --git a/fluid/PaddleCV/yolov3/reader.py b/fluid/PaddleCV/yolov3/reader.py index 55d195e84da4c159d1a63af1d8d41deb79dbc792..4a246bed1cd619d0f414efd91ccb582d61e3d5b7 100644 --- a/fluid/PaddleCV/yolov3/reader.py +++ b/fluid/PaddleCV/yolov3/reader.py @@ -267,8 +267,8 @@ def train(size=416, interval=10, pyreader_num=1, use_multiprocessing=True, - num_workers=8, - max_queue=24): + num_workers=12, + max_queue=32): generator = dsr.get_reader('train', size, batch_size, shuffle, mixup_iter, random_sizes) if not use_multiprocessing: @@ -302,6 +302,7 @@ def train(size=416, cnt += 1 if cnt % intervals == 0: idx = np.random.randint(len(random_sizes)) + print("Resizing: ", (idx + 10) * 32) finally: if enqueuer is not None: enqueuer.stop() diff --git a/fluid/PaddleCV/yolov3/train.py b/fluid/PaddleCV/yolov3/train.py index eb2020f529ab32b9e946fc62ef7e5178dcfde5fa..b86b64bf240017fb29255de1eb09146eea49775c 100644 --- a/fluid/PaddleCV/yolov3/train.py +++ b/fluid/PaddleCV/yolov3/train.py @@ -96,7 +96,7 @@ def train(): mixup_iter = cfg.max_iter - cfg.start_iter - cfg.no_mixup_iter if cfg.use_pyreader: - train_reader = reader.train(input_size, batch_size=int(hyperparams['batch'])/devices_num, shuffle=True, mixup_iter=mixup_iter, random_sizes=random_sizes, interval=10, pyreader_num=devices, use_multiprocessing=cfg.use_multiprocess) + train_reader = reader.train(input_size, batch_size=int(hyperparams['batch'])/devices_num, shuffle=True, mixup_iter=mixup_iter, random_sizes=random_sizes, interval=10, pyreader_num=devices_num, use_multiprocessing=cfg.use_multiprocess) py_reader = model.py_reader py_reader.decorate_paddle_reader(train_reader) else: