anchor generator
import numpy as np
import six
def generate_anchor_base(base_size=16, ratios=[0.5, 1, 2], anchor_sacles=[8, 16, 32]):
x_center = base_size / 2
y_center = base_size / 2
anchor_base = np.zeros(((len(ratios)*len(anchor_sacles)), 4), dtype = np.float32)
for i in six.moves.range(len(ratios)):
for j in six.moves.range(len(anchor_sacles)):
h = base_size * (np.sqrt(ratios[i])) * anchor_sacles[j]
w = base_size * (np.sqrt(1. / ratios[i])) * anchor_sacles[j]
index = i * len(anchor_sacles) + j
anchor_base[index, 0] = x_center - w/2
anchor_base[index, 1] = y_center - h/2
anchor_base[index, 2] = x_center + w/2
anchor_base[index, 3] = y_center + h/2
return anchor_base
print(generate_anchor_base())
版权声明:本文为Xueting_B原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。