本文整理汇总了Python中generate_anchors.generate_anchors方法的典型用法代码示例。如果您正苦于以下问题:Python generate_anchors.generate_anchors方法的具体用法?Python generate_anchors.generate_anchors怎么用?Python generate_anchors.generate_anchors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类generate_anchors
的用法示例。
在下文中一共展示了generate_anchors.generate_anchors方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
# parse the layer parameter string, which must be valid YAML
layer_params = yaml.load(self.param_str)
self._feat_stride = layer_params['feat_stride']
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
if DEBUG:
print 'feat_stride: {}'.format(self._feat_stride)
print 'anchors:'
print self._anchors
# rois blob: holds R regions of interest, each is a 5-tuple
# (n, x1, y1, x2, y2) specifying an image batch index n and a
# rectangle (x1, y1, x2, y2)
top[0].reshape(1, 5)
# scores blob: holds scores for R regions of interest
if len(top) > 1:
top[1].reshape(1, 1, 1, 1)
示例2: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
# parse the layer parameter string, which must be valid YAML
layer_params = yaml.load(self.param_str_)
self._feat_stride = layer_params['feat_stride']
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
if DEBUG:
print 'feat_stride: {}'.format(self._feat_stride)
print 'anchors:'
print self._anchors
# rois blob: holds R regions of interest, each is a 5-tuple
# (n, x1, y1, x2, y2) specifying an image batch index n and a
# rectangle (x1, y1, x2, y2)
top[0].reshape(1, 5)
# scores blob: holds scores for R regions of interest
if len(top) > 1:
top[1].reshape(1, 1, 1, 1)
示例3: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
# parse the layer parameter string, which must be valid YAML
layer_params = yaml.load(self.param_str_)
self._feat_stride = layer_params['feat_stride']
self._anchors = generate_anchors(cfg.TRAIN.RPN_BASE_SIZE, cfg.TRAIN.RPN_ASPECTS, cfg.TRAIN.RPN_SCALES)
self._num_anchors = self._anchors.shape[0]
if DEBUG:
print 'feat_stride: {}'.format(self._feat_stride)
print 'anchors:'
print self._anchors
# rois blob: holds R regions of interest, each is a 5-tuple
# (n, x1, y1, x2, y2) specifying an image batch index n and a
# rectangle (x1, y1, x2, y2)
top[0].reshape(1, 5)
# scores blob: holds scores for R regions of interest
if len(top) > 1:
top[1].reshape(1, 1, 1, 1)
示例4: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
layer_params = yaml.load(self.param_str_)
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
self._feat_stride = layer_params['feat_stride']
if DEBUG:
print 'anchors:'
print self._anchors
print 'anchor shapes:'
print np.hstack((
self._anchors[:, 2::4] - self._anchors[:, 0::4],
self._anchors[:, 3::4] - self._anchors[:, 1::4],
))
self._counts = cfg.EPS
self._sums = np.zeros((1, 4))
self._squared_sums = np.zeros((1, 4))
self._fg_sum = 0
self._bg_sum = 0
self._count = 0
# allow boxes to sit over the edge by a small amount
self._allowed_border = layer_params.get('allowed_border', 0)
height, width = bottom[0].data.shape[-2:]
if DEBUG:
print 'AnchorTargetLayer: height', height, 'width', width
A = self._num_anchors
# labels
top[0].reshape(1, 1, A * height, width)
# bbox_targets
top[1].reshape(1, A * 4, height, width)
# bbox_inside_weights
top[2].reshape(1, A * 4, height, width)
# bbox_outside_weights
top[3].reshape(1, A * 4, height, width)
示例5: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
self._anchors = generate_anchors(cfg.TRAIN.RPN_BASE_SIZE, cfg.TRAIN.RPN_ASPECTS, cfg.TRAIN.RPN_SCALES)
self._num_anchors = self._anchors.shape[0]
if DEBUG:
print 'anchors:'
print self._anchors
print 'anchor shapes:'
print np.hstack((
self._anchors[:, 2::4] - self._anchors[:, 0::4],
self._anchors[:, 3::4] - self._anchors[:, 1::4],
))
self._counts = cfg.EPS
self._sums = np.zeros((1, 4))
self._squared_sums = np.zeros((1, 4))
self._fg_sum = 0
self._bg_sum = 0
self._count = 0
layer_params = yaml.load(self.param_str_)
self._feat_stride = layer_params['feat_stride']
# allow boxes to sit over the edge by a small amount
self._allowed_border = layer_params.get('allowed_border', 0)
height, width = bottom[0].data.shape[-2:]
if DEBUG:
print 'AnchorTargetLayer: height', height, 'width', width
A = self._num_anchors
# labels
top[0].reshape(1, 1, A * height, width)
# bbox_targets
top[1].reshape(1, A * 4, height, width)
# bbox_inside_weights
top[2].reshape(1, A * 4, height, width)
# bbox_outside_weights
top[3].reshape(1, A * 4, height, width)
示例6: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
# parse the layer parameter string, which must be valid YAML
try:
layer_params = yaml.load(self.param_str_)
except AttributeError:
layer_params = yaml.load(self.param_str)
self._feat_stride = layer_params['feat_stride']
self._anchor_ratios = layer_params.get('ratios',(0.5, 1, 2))
anchor_scales = layer_params.get('scales', (8, 16, 32))
base_size = layer_params.get('base_size',16)
self._anchors = generate_anchors(scales=np.array(anchor_scales), base_size=base_size,ratios=np.array(self._anchor_ratios))
self._num_anchors = self._anchors.shape[0]
if DEBUG:
print 'feat_stride: {}'.format(self._feat_stride)
print 'anchors:'
print self._anchors
# rois blob: holds R regions of interest, each is a 5-tuple
# (n, x1, y1, x2, y2) specifying an image batch index n and a
# rectangle (x1, y1, x2, y2)
top[0].reshape(1, 5)
# scores blob: holds scores for R regions of interest
if len(top) > 1:
top[1].reshape(1, 1, 1, 1)
示例7: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
layer_params = yaml.load(self.param_str)
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
self._feat_stride = layer_params['feat_stride']
if DEBUG:
print 'anchors:'
print self._anchors
print 'anchor shapes:'
print np.hstack((
self._anchors[:, 2::4] - self._anchors[:, 0::4],
self._anchors[:, 3::4] - self._anchors[:, 1::4],
))
self._counts = cfg.EPS
self._sums = np.zeros((1, 4))
self._squared_sums = np.zeros((1, 4))
self._fg_sum = 0
self._bg_sum = 0
self._count = 0
# allow boxes to sit over the edge by a small amount
self._allowed_border = layer_params.get('allowed_border', 0)
height, width = bottom[0].data.shape[-2:]
if DEBUG:
print 'AnchorTargetLayer: height', height, 'width', width
A = self._num_anchors
# labels
top[0].reshape(1, 1, A * height, width)
# bbox_targets
top[1].reshape(1, A * 4, height, width)
# bbox_inside_weights
top[2].reshape(1, A * 4, height, width)
# bbox_outside_weights
top[3].reshape(1, A * 4, height, width)
示例8: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top, pre_nms_topN=12000, post_nms_topN=2000,
nms_thresh=0.7, min_size=16):
self._feat_stride = 16
anchor_scales = (8, 16, 32)
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
self.pre_nms_topN = pre_nms_topN
self.post_nms_topN = post_nms_topN
self.nms_thresh = nms_thresh
self.min_size = min_size
if DEBUG:
print('feat_stride: {}'.format(self._feat_stride))
print('anchors:')
print(self._anchors)
# rois blob: holds R regions of interest, each is a 5-tuple
# (n, x1, y1, x2, y2) specifying an image batch index n and a
# rectangle (x1, y1, x2, y2)
# top[0].reshape(1, 5)
# scores blob: holds scores for R regions of interest
# if len(top) > 1:
# top[1].reshape(1, 1, 1, 1)
示例9: __init__
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def __init__(self, feat_stride=16):
self.feat_stride = feat_stride
self.anchors = generate_anchors()
self.n_anchors = self.anchors.shape[0]
self.allowed_border = 0
示例10: __init__
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def __init__(self, feat_stride=16, anchor_scales=[4, 8, 16, 32]):
self._feat_stride = feat_stride
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
示例11: get_all_anchors
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def get_all_anchors(stride, sizes, ratios, max_size):
"""
Get all anchors in the largest possible image, shifted, floatbox
Returns:
anchors: SxSxNUM_ANCHORx4, where S == MAX_SIZE//STRIDE, floatbox
The layout in the NUM_ANCHOR dim is NUM_RATIO x NUM_SCALE.
"""
# Generates a NAx4 matrix of anchor boxes in (x1, y1, x2, y2) format. Anchors
# are centered on stride / 2, have (approximate) sqrt areas of the specified
# sizes, and aspect ratios as given.
# got all anchor start from center (8,8) [so the base box is (0,0,15,15)]
# -> ratios * scales
cell_anchors = generate_anchors(
stride, scales=np.array(sizes, dtype=np.float) / stride,
ratios=np.array(ratios, dtype=np.float))
# anchors are intbox here.
# anchors at featuremap [0,0] are centered at fpcoor (8,8) (half of stride)
# 1920/16 -> 120
# previous tensorpack code
#field_size = max_size // stride # how many anchor position in an image
# at one axis
field_size = int(np.ceil(max_size / stride))
# 0, 120, ...., 1920
# 120*120 (x,y)
shifts = np.arange(0, field_size) * stride # each position"s (x,y)
shift_x, shift_y = np.meshgrid(shifts, shifts)
shift_x = shift_x.flatten()
shift_y = shift_y.flatten()
# for 1920 , will be (120x120,4) # all the anchor boxes xy
# all anchor position xy, so should be [51x51, 4]
shifts = np.vstack((shift_x, shift_y, shift_x, shift_y)).transpose()
# Kx4, K = field_size * field_size
K = shifts.shape[0] # 1920 gets 120x120
A = cell_anchors.shape[0] # number of anchor at 1 position
field_of_anchors = (
cell_anchors.reshape((1, A, 4)) +
shifts.reshape((1, K, 4)).transpose((1, 0, 2)))
field_of_anchors = field_of_anchors.reshape((field_size, field_size, A, 4))
# FSxFSxAx4
# Many rounding happens inside the anchor code anyway
#assert np.all(field_of_anchors == field_of_anchors.astype("int32")),
#(field_of_anchors,field_of_anchors.astype("int32"))
# 1920 -> (120,120,NA,4)
field_of_anchors = field_of_anchors.astype("float32")
# the last 4 is (x1,y1,x2,y2)
# (x1,y1+1,x2+1,y2)??
field_of_anchors[:, :, :, [2, 3]] += 1
return field_of_anchors
# flatten a tensor
# [N,M,JI,JXP,dim] -> [N*M*JI,JXP,dim]
# keep how many dimension in the end, so final rank is keep + 1
示例12: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
try:
layer_params = yaml.load(self.param_str_)
except AttributeError:
layer_params = yaml.load(self.param_str)
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchor_ratios = layer_params.get('ratios',(0.5, 1, 2))
base_size = layer_params.get('base_size', 16)
self._anchors = generate_anchors(scales=np.array(anchor_scales), base_size=base_size,
ratios=np.array(self._anchor_ratios))
self._num_anchors = self._anchors.shape[0]
self._feat_stride = layer_params['feat_stride']
if DEBUG:
print 'anchors:'
print self._anchors
print 'anchor shapes:'
print np.hstack((
self._anchors[:, 2::4] - self._anchors[:, 0::4],
self._anchors[:, 3::4] - self._anchors[:, 1::4],
))
self._counts = cfg.EPS
self._sums = np.zeros((1, 4))
self._squared_sums = np.zeros((1, 4))
self._fg_sum = 0
self._bg_sum = 0
self._count = 0
# allow boxes to sit over the edge by a small amount
self._allowed_border = layer_params.get('allowed_border', 0)
height, width = bottom[0].data.shape[-2:]
if DEBUG:
print 'AnchorTargetLayer: height', height, 'width', width
A = self._num_anchors
# labels
top[0].reshape(1, 1, A * height, width)
# bbox_targets
top[1].reshape(1, A * 4, height, width)
# bbox_inside_weights
top[2].reshape(1, A * 4, height, width)
# bbox_outside_weights
top[3].reshape(1, A * 4, height, width)
示例13: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
try:
layer_params = yaml.load(self.param_str_)
except AttributeError:
layer_params = yaml.load(self.param_str)
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchor_ratios = layer_params.get('ratios', (0.5, 1, 2))
base_size = layer_params.get('base_size', 16)
self._anchors = generate_anchors(scales=np.array(anchor_scales), base_size=base_size,
ratios=np.array(self._anchor_ratios))
self._num_anchors = self._anchors.shape[0]
self._feat_stride = layer_params['feat_stride']
if DEBUG:
print 'anchors:'
print self._anchors
print 'anchor shapes:'
print np.hstack((
self._anchors[:, 2::4] - self._anchors[:, 0::4],
self._anchors[:, 3::4] - self._anchors[:, 1::4],
))
self._counts = cfg.EPS
self._sums = np.zeros((1, 4))
self._squared_sums = np.zeros((1, 4))
self._fg_sum = 0
self._bg_sum = 0
self._count = 0
# allow boxes to sit over the edge by a small amount
self._allowed_border = layer_params.get('allowed_border', 0)
height, width = bottom[0].data.shape[-2:]
if DEBUG:
print 'AnchorTargetLayer: height', height, 'width', width
A = self._num_anchors
# labels
top[0].reshape(cfg.TRAIN.IMS_PER_BATCH, 1, A * height, width)
# bbox_targets
top[1].reshape(cfg.TRAIN.IMS_PER_BATCH, A * 4, height, width)
# bbox_inside_weights
top[2].reshape(cfg.TRAIN.IMS_PER_BATCH, A * 4, height, width)
# bbox_outside_weights
top[3].reshape(cfg.TRAIN.IMS_PER_BATCH, A * 4, height, width)
示例14: setup
# 需要导入模块: import generate_anchors [as 别名]
# 或者: from generate_anchors import generate_anchors [as 别名]
def setup(self, bottom, top):
# layer_params = yaml.load(self.param_str_)
layer_params = dict()
layer_params['feat_stride'] = 16
layer_params['scales'] = (8, 16, 32)
layer_params['allowed_border'] = 0
self.RPN_NEGATIVE_OVERLAP = 0.3
self.RPN_POSITIVE_OVERLAP = 0.7
self.RPN_FG_FRACTION = 0.5
self.RPN_BATCHSIZE = 256
self.EPS = 1e-14
self.RPN_BBOX_INSIDE_WEIGHTS = 1
self.RPN_POSITIVE_WEIGHT = -1
anchor_scales = layer_params.get('scales', (8, 16, 32))
self._anchors = generate_anchors(scales=np.array(anchor_scales))
self._num_anchors = self._anchors.shape[0]
self._feat_stride = layer_params['feat_stride']
if DEBUG:
# print 'anchors:'
# print self._anchors
# print 'anchor shapes:'
# print np.hstack((
# self._anchors[:, 2::4] - self._anchors[:, 0::4],
# self._anchors[:, 3::4] - self._anchors[:, 1::4],
# ))
self._counts = self.EPS
self._sums = np.zeros((1, 4))
self._squared_sums = np.zeros((1, 4))
self._fg_sum = 0
self._bg_sum = 0
self._count = 0
# allow boxes to sit over the edge by a small amount
self._allowed_border = layer_params.get('allowed_border', 0)
# height, width = bottom[0].data.shape[-2:]
# if DEBUG:
# print 'AnchorTargetLayer: height', height, 'width', width
# labels
# top[0].reshape(1, 1, A * height, width)
# # bbox_targets
# top[1].reshape(1, A * 4, height, width)
# # bbox_inside_weights
# top[2].reshape(1, A * 4, height, width)
# # bbox_outside_weights
# top[3].reshape(1, A * 4, height, width)