未验证 提交 a9c8aa2c 编写于 作者: B Bai Yifan 提交者: GitHub

Fix data-anchor-sampling and use depthwise conv (#1188)

* fix data-anchor-sampling and use depthwise conv
上级 06ab0c69
...@@ -123,25 +123,34 @@ def data_anchor_sampling(sampler, bbox_labels, image_width, image_height, ...@@ -123,25 +123,34 @@ def data_anchor_sampling(sampler, bbox_labels, image_width, image_height,
hei = image_height * (norm_ymax - norm_ymin) hei = image_height * (norm_ymax - norm_ymin)
range_size = 0 range_size = 0
area = wid * hei
for scale_ind in range(0, len(scale_array) - 1): for scale_ind in range(0, len(scale_array) - 1):
area = wid * hei
if area > scale_array[scale_ind] ** 2 and area < \ if area > scale_array[scale_ind] ** 2 and area < \
scale_array[scale_ind + 1] ** 2: scale_array[scale_ind + 1] ** 2:
range_size = scale_ind + 1 range_size = scale_ind + 1
break break
if area > scale_array[len(scale_array) - 2]**2:
range_size = len(scale_array) - 2
scale_choose = 0.0 scale_choose = 0.0
if range_size == 0: if range_size == 0:
rand_idx_size = range_size + 1 rand_idx_size = 0
else: else:
# np.random.randint range: [low, high) # np.random.randint range: [low, high)
rng_rand_size = np.random.randint(0, range_size + 1) rng_rand_size = np.random.randint(0, range_size + 1)
rand_idx_size = rng_rand_size % (range_size + 1) rand_idx_size = rng_rand_size % (range_size + 1)
min_resize_val = scale_array[rand_idx_size] / 2.0 if rand_idx_size == range_size:
max_resize_val = min(2.0 * scale_array[rand_idx_size], min_resize_val = scale_array[rand_idx_size] / 2.0
2 * math.sqrt(wid * hei)) max_resize_val = min(2.0 * scale_array[rand_idx_size],
scale_choose = np.random.uniform(min_resize_val, max_resize_val) 2 * math.sqrt(wid * hei))
scale_choose = random.uniform(min_resize_val, max_resize_val)
else:
min_resize_val = scale_array[rand_idx_size] / 2.0
max_resize_val = 2.0 * scale_array[rand_idx_size]
scale_choose = random.uniform(min_resize_val, max_resize_val)
sample_bbox_size = wid * resize_width / scale_choose sample_bbox_size = wid * resize_width / scale_choose
w_off_orig = 0.0 w_off_orig = 0.0
...@@ -178,6 +187,8 @@ def data_anchor_sampling(sampler, bbox_labels, image_width, image_height, ...@@ -178,6 +187,8 @@ def data_anchor_sampling(sampler, bbox_labels, image_width, image_height,
w_off + float(sample_bbox_size / image_width), w_off + float(sample_bbox_size / image_width),
h_off + float(sample_bbox_size / image_height)) h_off + float(sample_bbox_size / image_height))
return sampled_bbox return sampled_bbox
else:
return 0
def jaccard_overlap(sample_bbox, object_bbox): def jaccard_overlap(sample_bbox, object_bbox):
...@@ -265,6 +276,8 @@ def generate_batch_random_samples(batch_sampler, bbox_labels, image_width, ...@@ -265,6 +276,8 @@ def generate_batch_random_samples(batch_sampler, bbox_labels, image_width,
sample_bbox = data_anchor_sampling( sample_bbox = data_anchor_sampling(
sampler, bbox_labels, image_width, image_height, scale_array, sampler, bbox_labels, image_width, image_height, scale_array,
resize_width, resize_height) resize_width, resize_height)
if sample_bbox == 0:
break
if satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): if satisfy_sample_constraint(sampler, sample_bbox, bbox_labels):
sampled_bbox.append(sample_bbox) sampled_bbox.append(sample_bbox)
found = found + 1 found = found + 1
......
...@@ -144,7 +144,7 @@ class PyramidBox(object): ...@@ -144,7 +144,7 @@ class PyramidBox(object):
groups=ch, groups=ch,
param_attr=w_attr, param_attr=w_attr,
bias_attr=False, bias_attr=False,
use_cudnn=True) use_cudnn=False)
else: else:
upsampling = fluid.layers.resize_bilinear( upsampling = fluid.layers.resize_bilinear(
conv1, out_shape=up_to.shape[2:]) conv1, out_shape=up_to.shape[2:])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册