提交 8ceb9849 编写于 作者: D dengkaipeng

remove center constraint in box_crop

上级 3be84530
......@@ -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')
......
......@@ -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
......
......@@ -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],
......
......@@ -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()
......
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册