本文整理汇总了Python中bbox.bbox_transform.bbox_transform方法的典型用法代码示例。如果您正苦于以下问题:Python bbox_transform.bbox_transform方法的具体用法?Python bbox_transform.bbox_transform怎么用?Python bbox_transform.bbox_transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bbox.bbox_transform
的用法示例。
在下文中一共展示了bbox_transform.bbox_transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample_rois_v2
# 需要导入模块: from bbox import bbox_transform [as 别名]
# 或者: from bbox.bbox_transform import bbox_transform [as 别名]
def sample_rois_v2(rois, num_classes, cfg,
labels=None, overlaps=None, bbox_targets=None, gt_boxes=None):
"""
generate random sample of ROIs comprising foreground and background examples
:param rois: all_rois [n, 4]; e2e: [n, 5] with batch_index
:param fg_rois_per_image: foreground roi number
:param rois_per_image: total roi number
:param num_classes: number of classes
:param labels: maybe precomputed
:param overlaps: maybe precomputed (max_overlaps)
:param bbox_targets: maybe precomputed
:param gt_boxes: optional for e2e [n, 5] (x1, y1, x2, y2, cls)
:return: (labels, rois, bbox_targets, bbox_weights)
"""
if labels is None:
overlaps = bbox_overlaps(rois[:, 1:].astype(np.float), gt_boxes[:, :4].astype(np.float))
gt_assignment = overlaps.argmax(axis=1)
overlaps = overlaps.max(axis=1)
labels = gt_boxes[gt_assignment, 4]
# set labels of bg_rois to be 0
bg_ind = np.where(overlaps < cfg.TRAIN.BG_THRESH_HI)[0]
labels[bg_ind] = 0
# load or compute bbox_target
if bbox_targets is not None:
bbox_target_data = bbox_targets
else:
targets = bbox_transform(rois[:, 1:], gt_boxes[gt_assignment, :4])
if cfg.TRAIN.BBOX_NORMALIZATION_PRECOMPUTED:
targets = ((targets - np.array(cfg.TRAIN.BBOX_MEANS))
/ np.array(cfg.TRAIN.BBOX_STDS))
bbox_target_data = np.hstack((labels[:, np.newaxis], targets))
bbox_targets, bbox_weights = \
expand_bbox_regression_targets(bbox_target_data, num_classes, cfg)
return rois, labels, bbox_targets, bbox_weights
示例2: get_delta_roi
# 需要导入模块: from bbox import bbox_transform [as 别名]
# 或者: from bbox.bbox_transform import bbox_transform [as 别名]
def get_delta_roi(filename, roi_rec, im_scale):
trackid = roi_rec['gt_trackid']
boxes = roi_rec['boxes']
boxes = boxes * im_scale
delta = np.zeros_like(roi_rec['boxes'], dtype=float)
dic = {}
tree = ET.parse(filename)
size = tree.find('size')
height = float(size.find('height').text)
width = float(size.find('width').text)
objs = tree.findall('object')
for obj in objs:
bbox = obj.find('bndbox')
if roi_rec['flipped']==False:
np.minimum(float(bbox.find('ymax').text), roi_rec['height']-1)
dic[int(obj.find('trackid').text)] = [np.maximum(float(bbox.find('xmin').text), 0)*im_scale,
np.maximum(float(bbox.find('ymin').text), 0)*im_scale,
np.minimum(float(bbox.find('xmax').text), roi_rec['width']-1)*im_scale,
np.minimum(float(bbox.find('ymax').text), roi_rec['height']-1)*im_scale]
else:
xmin = np.maximum(float(bbox.find('xmin').text), 0)
ymin = np.maximum(float(bbox.find('ymin').text), 0)
xmax = np.minimum(float(bbox.find('xmax').text), roi_rec['width']-1)
ymax = np.minimum(float(bbox.find('ymax').text), roi_rec['height']-1)
xmin_flip = width - 1 - xmax
xmax_flip = width - 1 - xmin
assert xmax_flip >= xmin_flip
dic[int(obj.find('trackid').text)] = [xmin_flip*im_scale, ymin*im_scale, xmax_flip*im_scale, ymax*im_scale]
for i in range(len(trackid)):
if trackid[i] in dic:
delta_trans = bbox_transform(np.array([boxes[i]]), np.array([dic[trackid[i]]]))
delta[i][:] = delta_trans[0]
return delta