本文整理汇总了Python中fast_rcnn.config.cfg.EPS属性的典型用法代码示例。如果您正苦于以下问题:Python cfg.EPS属性的具体用法?Python cfg.EPS怎么用?Python cfg.EPS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类fast_rcnn.config.cfg
的用法示例。
在下文中一共展示了cfg.EPS属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compute_targets
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [as 别名]
def _compute_targets(ex_rois, gt_rois):
"""Compute bounding-box regression targets for an image. The targets are scale invariance"""
ex_widths = ex_rois[:, 2] - ex_rois[:, 0] + cfg.EPS
ex_heights = ex_rois[:, 3] - ex_rois[:, 1] + cfg.EPS
ex_ctr_x = ex_rois[:, 0] + 0.5 * ex_widths
ex_ctr_y = ex_rois[:, 1] + 0.5 * ex_heights
gt_widths = gt_rois[:, 2] - gt_rois[:, 0] + cfg.EPS
gt_heights = gt_rois[:, 3] - gt_rois[:, 1] + cfg.EPS
gt_ctr_x = gt_rois[:, 0] + 0.5 * gt_widths
gt_ctr_y = gt_rois[:, 1] + 0.5 * gt_heights
targets_dx = (gt_ctr_x - ex_ctr_x) / ex_widths
targets_dy = (gt_ctr_y - ex_ctr_y) / ex_heights
targets_dw = np.log(gt_widths / ex_widths)
targets_dh = np.log(gt_heights / ex_heights)
targets = np.zeros((ex_rois.shape[0], 4), dtype=np.float32)
targets[:, 0] = targets_dx
targets[:, 1] = targets_dy
targets[:, 2] = targets_dw
targets[:, 3] = targets_dh
return targets
示例2: setup
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [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)
示例3: setup
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [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)
示例4: add_bbox_regression_targets
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [as 别名]
def add_bbox_regression_targets(roidb):
"""Add information needed to train bounding-box regressors."""
assert len(roidb) > 0
assert 'info_boxes' in roidb[0], 'Did you call prepare_roidb first?'
num_images = len(roidb)
# Infer number of classes from the number of columns in gt_overlaps
num_classes = roidb[0]['gt_overlaps'].shape[1]
# Compute values needed for means and stds
# var(x) = E(x^2) - E(x)^2
class_counts = np.zeros((num_classes, 1)) + cfg.EPS
sums = np.zeros((num_classes, 4))
squared_sums = np.zeros((num_classes, 4))
for im_i in xrange(num_images):
targets = roidb[im_i]['info_boxes']
for cls in xrange(1, num_classes):
cls_inds = np.where(targets[:, 12] == cls)[0]
if cls_inds.size > 0:
class_counts[cls] += cls_inds.size
sums[cls, :] += targets[cls_inds, 14:].sum(axis=0)
squared_sums[cls, :] += (targets[cls_inds, 14:] ** 2).sum(axis=0)
means = sums / class_counts
stds = np.sqrt(squared_sums / class_counts - means ** 2)
# Normalize targets
for im_i in xrange(num_images):
targets = roidb[im_i]['info_boxes']
for cls in xrange(1, num_classes):
cls_inds = np.where(targets[:, 12] == cls)[0]
roidb[im_i]['info_boxes'][cls_inds, 14:] -= means[cls, :]
if stds[cls, 0] != 0:
roidb[im_i]['info_boxes'][cls_inds, 14:] /= stds[cls, :]
# These values will be needed for making predictions
# (the predicts will need to be unnormalized and uncentered)
return means.ravel(), stds.ravel()
示例5: setup
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [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)
示例6: compute_bbox_target_normalization
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [as 别名]
def compute_bbox_target_normalization(roidb):
num_images = len(roidb)
# Infer number of classes from the number of columns in gt_overlaps
num_classes = roidb[0]['gt_overlaps'].shape[1]
for im_i in xrange(num_images):
rois = roidb[im_i]['boxes']
max_overlaps = roidb[im_i]['max_overlaps']
max_classes = roidb[im_i]['max_classes']
roidb[im_i]['bbox_targets'], roidb[im_i]['gt_ind_assignments'] = \
_compute_targets(rois, max_overlaps, max_classes)
class_counts = np.zeros((num_classes, 1)) + cfg.EPS
sums = np.zeros((num_classes, 4))
squared_sums = np.zeros((num_classes, 4))
for im_i in xrange(num_images):
targets = roidb[im_i]['bbox_targets']
image_target_classes = np.unique(targets[:, 0]).astype(int)
for cls in image_target_classes:
if(cls > 0):
cls_inds = np.where(targets[:, 0] == cls)[0]
class_counts[cls] += cls_inds.size
sums[cls, :] += targets[cls_inds, 1:].sum(axis=0)
squared_sums[cls, :] += \
(targets[cls_inds, 1:] ** 2).sum(axis=0)
means = sums / class_counts
stds = np.sqrt(squared_sums / class_counts - means ** 2)
np.save(cfg.TRAIN.BBOX_TARGET_NORMALIZATION_FILE, {'means': means, 'stds': stds})
if cfg.TRAIN.BBOX_NORMALIZE_TARGETS:
print "Normalizing targets"
for im_i in xrange(num_images):
targets = roidb[im_i]['bbox_targets']
image_target_classes = np.unique(targets[:, 0]).astype(int)
for cls in image_target_classes:
if(cls > 0):
cls_inds = np.where(targets[:, 0] == cls)[0]
roidb[im_i]['bbox_targets'][cls_inds, 1:] -= means[cls, :]
roidb[im_i]['bbox_targets'][cls_inds, 1:] /= stds[cls, :]
else:
print "NOT normalizing targets"
return means, stds
示例7: add_bbox_regression_targets
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [as 别名]
def add_bbox_regression_targets(roidb):
"""Add information needed to train bounding-box regressors."""
assert len(roidb) > 0
assert 'max_classes' in roidb[0], 'Did you call prepare_roidb first?'
num_images = len(roidb)
# Infer number of classes from the number of columns in gt_overlaps
num_classes = roidb[0]['gt_overlaps'].shape[1]
for im_i in xrange(num_images):
rois = roidb[im_i]['boxes']
max_overlaps = roidb[im_i]['max_overlaps']
max_classes = roidb[im_i]['max_classes']
roidb[im_i]['bbox_targets'] = \
_compute_targets(rois, max_overlaps, max_classes, num_classes)
# Compute values needed for means and stds
# var(x) = E(x^2) - E(x)^2
class_counts = np.zeros((num_classes, 1)) + cfg.EPS
sums = np.zeros((num_classes, 4))
squared_sums = np.zeros((num_classes, 4))
for im_i in xrange(num_images):
targets = roidb[im_i]['bbox_targets']
for cls in xrange(1, num_classes):
cls_inds = np.where(targets[:, 0] == cls)[0]
if cls_inds.size > 0:
class_counts[cls] += cls_inds.size
sums[cls, :] += targets[cls_inds, 1:].sum(axis=0)
squared_sums[cls, :] += (targets[cls_inds, 1:] ** 2).sum(axis=0)
means = sums / class_counts
stds = np.sqrt(squared_sums / class_counts - means ** 2)
# Normalize targets
for im_i in xrange(num_images):
targets = roidb[im_i]['bbox_targets']
for cls in xrange(1, num_classes):
cls_inds = np.where(targets[:, 0] == cls)[0]
roidb[im_i]['bbox_targets'][cls_inds, 1:] -= means[cls, :]
if stds[cls, 0] != 0:
roidb[im_i]['bbox_targets'][cls_inds, 1:] /= stds[cls, :]
# These values will be needed for making predictions
# (the predicts will need to be unnormalized and uncentered)
return means.ravel(), stds.ravel()
示例8: _compute_targets
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [as 别名]
def _compute_targets(rois, overlaps, labels, num_classes):
"""Compute bounding-box regression targets for an image."""
# Ensure ROIs are floats
rois = rois.astype(np.float, copy=False)
# Indices of ground-truth ROIs
gt_inds = np.where(overlaps == 1)[0]
# Indices of examples for which we try to make predictions
ex_inds = []
for i in xrange(1, num_classes):
ex_inds.extend( np.where((labels == i) & (overlaps >= cfg.TRAIN.BBOX_THRESH))[0] )
# Get IoU overlap between each ex ROI and gt ROI
ex_gt_overlaps = utils.cython_bbox.bbox_overlaps(rois[ex_inds, :],
rois[gt_inds, :])
# Find which gt ROI each ex ROI has max overlap with:
# this will be the ex ROI's gt target
if ex_gt_overlaps.shape[0] != 0:
gt_assignment = ex_gt_overlaps.argmax(axis=1)
else:
gt_assignment = []
gt_rois = rois[gt_inds[gt_assignment], :]
ex_rois = rois[ex_inds, :]
ex_widths = ex_rois[:, 2] - ex_rois[:, 0] + cfg.EPS
ex_heights = ex_rois[:, 3] - ex_rois[:, 1] + cfg.EPS
ex_ctr_x = ex_rois[:, 0] + 0.5 * ex_widths
ex_ctr_y = ex_rois[:, 1] + 0.5 * ex_heights
gt_widths = gt_rois[:, 2] - gt_rois[:, 0] + cfg.EPS
gt_heights = gt_rois[:, 3] - gt_rois[:, 1] + cfg.EPS
gt_ctr_x = gt_rois[:, 0] + 0.5 * gt_widths
gt_ctr_y = gt_rois[:, 1] + 0.5 * gt_heights
targets_dx = (gt_ctr_x - ex_ctr_x) / ex_widths
targets_dy = (gt_ctr_y - ex_ctr_y) / ex_heights
targets_dw = np.log(gt_widths / ex_widths)
targets_dh = np.log(gt_heights / ex_heights)
targets = np.zeros((rois.shape[0], 5), dtype=np.float32)
targets[ex_inds, 0] = labels[ex_inds]
targets[ex_inds, 1] = targets_dx
targets[ex_inds, 2] = targets_dy
targets[ex_inds, 3] = targets_dw
targets[ex_inds, 4] = targets_dh
return targets
示例9: setup
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [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)
示例10: setup
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [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)
示例11: _compute_targets
# 需要导入模块: from fast_rcnn.config import cfg [as 别名]
# 或者: from fast_rcnn.config.cfg import EPS [as 别名]
def _compute_targets(rois, overlaps, labels, num_classes):
"""Compute bounding-box regression targets for an image."""
# Ensure ROIs are floats
rois = rois.astype(np.float, copy=False)
# Indices of ground-truth ROIs
gt_inds = np.where(overlaps == 1)[0]
# Indices of examples for which we try to make predictions
ex_inds = []
for i in xrange(1, num_classes):
ex_inds.extend( np.where((labels == i) & (overlaps >= cfg.TRAIN.BBOX_THRESH[i-1]))[0] )
# Get IoU overlap between each ex ROI and gt ROI
ex_gt_overlaps = utils.cython_bbox.bbox_overlaps(rois[ex_inds, :],
rois[gt_inds, :])
# Find which gt ROI each ex ROI has max overlap with:
# this will be the ex ROI's gt target
if ex_gt_overlaps.shape[0] != 0:
gt_assignment = ex_gt_overlaps.argmax(axis=1)
else:
gt_assignment = []
gt_rois = rois[gt_inds[gt_assignment], :]
ex_rois = rois[ex_inds, :]
ex_widths = ex_rois[:, 2] - ex_rois[:, 0] + cfg.EPS
ex_heights = ex_rois[:, 3] - ex_rois[:, 1] + cfg.EPS
ex_ctr_x = ex_rois[:, 0] + 0.5 * ex_widths
ex_ctr_y = ex_rois[:, 1] + 0.5 * ex_heights
gt_widths = gt_rois[:, 2] - gt_rois[:, 0] + cfg.EPS
gt_heights = gt_rois[:, 3] - gt_rois[:, 1] + cfg.EPS
gt_ctr_x = gt_rois[:, 0] + 0.5 * gt_widths
gt_ctr_y = gt_rois[:, 1] + 0.5 * gt_heights
targets_dx = (gt_ctr_x - ex_ctr_x) / ex_widths
targets_dy = (gt_ctr_y - ex_ctr_y) / ex_heights
targets_dw = np.log(gt_widths / ex_widths)
targets_dh = np.log(gt_heights / ex_heights)
targets = np.zeros((rois.shape[0], 5), dtype=np.float32)
targets[ex_inds, 0] = labels[ex_inds]
targets[ex_inds, 1] = targets_dx
targets[ex_inds, 2] = targets_dy
targets[ex_inds, 3] = targets_dw
targets[ex_inds, 4] = targets_dh
return targets