本文整理汇总了Python中utils.boxes.bbox_transform_inv方法的典型用法代码示例。如果您正苦于以下问题:Python boxes.bbox_transform_inv方法的具体用法?Python boxes.bbox_transform_inv怎么用?Python boxes.bbox_transform_inv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.boxes
的用法示例。
在下文中一共展示了boxes.bbox_transform_inv方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compute_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def _compute_targets(ex_rois, gt_rois, labels, stage=0):
"""Compute bounding-box regression targets for an image."""
assert ex_rois.shape[0] == gt_rois.shape[0]
assert ex_rois.shape[1] == 4
assert gt_rois.shape[1] == 4
if cfg.FAST_RCNN.USE_CASCADE:
bbox_reg_weights = cfg.CASCADE_RCNN.BBOX_REG_WEIGHTS[stage]
else:
bbox_reg_weights = cfg.MODEL.BBOX_REG_WEIGHTS
targets = box_utils.bbox_transform_inv(ex_rois, gt_rois, bbox_reg_weights)
# Use class "1" for all fg boxes if using class_agnostic_bbox_reg
if cfg.MODEL.CLS_AGNOSTIC_BBOX_REG:
labels.clip(max=1, out=labels)
return np.hstack((labels[:, np.newaxis], targets)).astype(
np.float32, copy=False)
示例2: compute_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def compute_targets(ex_rois, gt_rois, weights=(1.0, 1.0, 1.0, 1.0)):
"""Compute bounding-box regression targets for an image."""
return box_utils.bbox_transform_inv(ex_rois, gt_rois, weights).astype(
np.float32, copy=False
)
示例3: _compute_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def _compute_targets(ex_rois, gt_rois, labels):
"""Compute bounding-box regression targets for an image."""
assert ex_rois.shape[0] == gt_rois.shape[0]
assert ex_rois.shape[1] == 4
assert gt_rois.shape[1] == 4
targets = box_utils.bbox_transform_inv(ex_rois, gt_rois,
cfg.MODEL.BBOX_REG_WEIGHTS)
# Use class "1" for all fg boxes if using class_agnostic_bbox_reg
if cfg.MODEL.CLS_AGNOSTIC_BBOX_REG:
labels.clip(max=1, out=labels)
return np.hstack((labels[:, np.newaxis], targets)).astype(
np.float32, copy=False)
示例4: _compute_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def _compute_targets(entry):
"""Compute bounding-box regression targets for an image."""
# Indices of ground-truth ROIs
rois = entry['boxes']
overlaps = entry['max_overlaps']
labels = entry['max_classes']
gt_inds = np.where((entry['gt_classes'] > 0) & (entry['is_crowd'] == 0))[0]
# Targets has format (class, tx, ty, tw, th)
targets = np.zeros((rois.shape[0], 5), dtype=np.float32)
if len(gt_inds) == 0:
# Bail if the image has no ground-truth ROIs
return targets
# Indices of examples for which we try to make predictions
ex_inds = np.where(overlaps >= cfg.TRAIN.BBOX_THRESH)[0]
# Get IoU overlap between each ex ROI and gt ROI
ex_gt_overlaps = box_utils.bbox_overlaps(
rois[ex_inds, :].astype(dtype=np.float32, copy=False),
rois[gt_inds, :].astype(dtype=np.float32, copy=False))
# Find which gt ROI each ex ROI has max overlap with:
# this will be the ex ROI's gt target
gt_assignment = ex_gt_overlaps.argmax(axis=1)
gt_rois = rois[gt_inds[gt_assignment], :]
ex_rois = rois[ex_inds, :]
# Use class "1" for all boxes if using class_agnostic_bbox_reg
targets[ex_inds, 0] = (
1 if cfg.MODEL.CLS_AGNOSTIC_BBOX_REG else labels[ex_inds])
targets[ex_inds, 1:] = box_utils.bbox_transform_inv(
ex_rois, gt_rois, cfg.MODEL.BBOX_REG_WEIGHTS)
return targets
示例5: test_bbox_transform_and_inverse
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def test_bbox_transform_and_inverse(self):
weights = (5, 5, 10, 10)
src_boxes = random_boxes([10, 10, 20, 20], 1, 10)
dst_boxes = random_boxes([10, 10, 20, 20], 1, 10)
deltas = box_utils.bbox_transform_inv(
src_boxes, dst_boxes, weights=weights
)
dst_boxes_reconstructed = box_utils.bbox_transform(
src_boxes, deltas, weights=weights
)
np.testing.assert_array_almost_equal(
dst_boxes, dst_boxes_reconstructed, decimal=5
)
示例6: test_bbox_dataset_to_prediction_roundtrip
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def test_bbox_dataset_to_prediction_roundtrip(self):
"""Simulate the process of reading a ground-truth box from a dataset,
make predictions from proposals, convert the predictions back to the
dataset format, and then use the COCO API to compute IoU overlap between
the gt box and the predictions. These should have IoU of 1.
"""
weights = (5, 5, 10, 10)
# 1/ "read" a box from a dataset in the default (x1, y1, w, h) format
gt_xywh_box = [10, 20, 100, 150]
# 2/ convert it to our internal (x1, y1, x2, y2) format
gt_xyxy_box = box_utils.xywh_to_xyxy(gt_xywh_box)
# 3/ consider nearby proposal boxes
prop_xyxy_boxes = random_boxes(gt_xyxy_box, 10, 10)
# 4/ compute proposal-to-gt transformation deltas
deltas = box_utils.bbox_transform_inv(
prop_xyxy_boxes, np.array([gt_xyxy_box]), weights=weights
)
# 5/ use deltas to transform proposals to xyxy predicted box
pred_xyxy_boxes = box_utils.bbox_transform(
prop_xyxy_boxes, deltas, weights=weights
)
# 6/ convert xyxy predicted box to xywh predicted box
pred_xywh_boxes = box_utils.xyxy_to_xywh(pred_xyxy_boxes)
# 7/ use COCO API to compute IoU
not_crowd = [int(False)] * pred_xywh_boxes.shape[0]
ious = COCOmask.iou(pred_xywh_boxes, np.array([gt_xywh_box]), not_crowd)
np.testing.assert_array_almost_equal(ious, np.ones(ious.shape))
示例7: _compute_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def _compute_targets(ex_rois, gt_rois, labels):
"""Compute bounding-box regression targets for an image."""
assert ex_rois.shape[0] == gt_rois.shape[0]
assert ex_rois.shape[1] == 4
assert gt_rois.shape[1] == 4
targets = box_utils.bbox_transform_inv(
ex_rois, gt_rois, cfg.MODEL.BBOX_REG_WEIGHTS
)
return np.hstack((labels[:, np.newaxis], targets)).astype(
np.float32, copy=False
)
示例8: get_location_info
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def get_location_info(human_boxes, object_boxes, union_boxes):
assert human_boxes.shape[1] == object_boxes.shape[1] == union_boxes.shape[1] == 4
human_object_loc = box_utils.bbox_transform_inv(human_boxes, object_boxes)
human_union_loc = box_utils.bbox_transform_inv(human_boxes, union_boxes)
object_union_loc = box_utils.bbox_transform_inv(object_boxes, union_boxes)
return np.concatenate((human_object_loc, human_union_loc, object_union_loc), axis=1)
示例9: _compute_action_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def _compute_action_targets(person_rois, gt_boxes, role_ids):
'''
Compute action targets
:param person_rois: rois assigned to gt acting-human, n * 4
:param gt_boxes: all gt boxes in one image
:param role_ids: person_rois_num * action_cls_num * NUM_TARGET_OBJECT_TYPES,
store person rois corresponding role object ids.
:return:
'''
assert person_rois.shape[0] == role_ids.shape[0]
# ToDo: should use cfg.MODEL.BBOX_REG_WEIGHTS?
# calculate targets between every person rois and every gt_boxes
targets = box_utils.bbox_transform_inv(np.repeat(person_rois, gt_boxes.shape[0], axis=0),
np.tile(gt_boxes, (person_rois.shape[0], 1)),
(1., 1., 1., 1.)).reshape(person_rois.shape[0], gt_boxes.shape[0], -1)
# human action targets is (person_num: 16, action_num: 26, role_cls: 2, relative_location: 4)
human_action_targets = np.zeros((role_ids.shape[0], role_ids.shape[1],
role_ids.shape[2], 4), dtype=np.float32)
action_target_weights = np.zeros_like(human_action_targets, dtype=np.float32)
# get action targets relative location
human_action_targets[np.where(role_ids > -1)] = \
targets[np.where(role_ids > -1)[0], role_ids[np.where(role_ids > -1)].astype(int)]
action_target_weights[np.where(role_ids > -1)] = 1.
return human_action_targets.reshape(-1, cfg.VCOCO.NUM_ACTION_CLASSES * cfg.VCOCO.NUM_TARGET_OBJECT_TYPES * 4), \
action_target_weights.reshape(-1, cfg.VCOCO.NUM_ACTION_CLASSES * cfg.VCOCO.NUM_TARGET_OBJECT_TYPES * 4)
示例10: _compute_action_targets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def _compute_action_targets(person_rois, gt_boxes, role_ids):
'''
Compute action targets
:param person_rois: rois assigned to gt acting-human, n * 4
:param gt_boxes: all gt boxes in one image
:param role_ids: person_rois_num * action_cls_num * num_target_object_types, store person rois corresponding role object ids
:return:
'''
assert person_rois.shape[0] == role_ids.shape[0]
# should use cfg.MODEL.BBOX_REG_WEIGHTS?
# calculate targets between every person rois and every gt_boxes
targets = box_utils.bbox_transform_inv(np.repeat(person_rois, gt_boxes.shape[0], axis=0),
np.tile(gt_boxes, (person_rois.shape[0], 1)),
(1., 1., 1., 1.)).reshape(person_rois.shape[0], gt_boxes.shape[0], -1)
# human action targets is (person_num: 16, action_num: 26, role_cls: 2, relative_location: 4)
# don't use np.inf, so that actions without target_objects could kept
human_action_targets = np.zeros((role_ids.shape[0], role_ids.shape[1],
role_ids.shape[2], 4), dtype=np.float32)
action_target_weights = np.zeros_like(human_action_targets, dtype=np.float32)
# get action targets relative location
human_action_targets[np.where(role_ids > -1)] = \
targets[np.where(role_ids > -1)[0], role_ids[np.where(role_ids > -1)].astype(int)]
action_target_weights[np.where(role_ids > -1)] = 1.
return human_action_targets.reshape(-1, cfg.VCOCO.NUM_ACTION_CLASSES * 2 * 4), \
action_target_weights.reshape(-1, cfg.VCOCO.NUM_ACTION_CLASSES * 2 * 4)
# ------------------------------- HOI union ------------------------------------
示例11: generate_triplets
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import bbox_transform_inv [as 别名]
def generate_triplets(human_boxes, object_boxes):
human_inds, object_inds = np.meshgrid(np.arange(human_boxes.shape[0]),
np.arange(object_boxes.shape[0]), indexing='ij')
human_inds, object_inds = human_inds.reshape(-1), object_inds.reshape(-1)
union_boxes = box_utils.get_union_box(human_boxes[human_inds][:, 1:],
object_boxes[object_inds][:, 1:])
union_boxes = np.hstack((np.zeros((union_boxes.shape[0], 1), dtype=union_boxes.dtype), union_boxes))
spatial_info = box_utils.bbox_transform_inv(human_boxes[human_inds][:, 1:],
object_boxes[object_inds][:, 1:])
return human_inds, object_inds, union_boxes, spatial_info
# --------------------- Check bottleneck ---------------------------