예제 #1
0
def _compute_targets(ex_rois, gt_rois, labels, num_classes):
    """
  This function expands those targets into the 4-of-4*K representation used
  by the network (i.e. only one class has non-zero targets).

  Returns:
    bbox_target (ndarray): N x 4K blob of regression targets
    bbox_inside_weights (ndarray): N x 4K blob of loss weights
  """

    assert ex_rois.shape[0] == gt_rois.shape[0]
    assert ex_rois.shape[1] == 4
    assert gt_rois.shape[1] == 4

    targets = bbox_transform(ex_rois, gt_rois)

    clss = labels
    bbox_targets = np.zeros((clss.size, 4 * num_classes), dtype=np.float32)
    bbox_inside_weights = np.zeros(bbox_targets.shape, dtype=np.float32)
    inds = np.where(clss > 0)[0]
    for ind in inds:
        cls = int(clss[ind])
        start = 4 * cls
        end = start + 4
        bbox_targets[ind, start:end] = targets[ind, 0:4]
        bbox_inside_weights[ind, start:end] = 1
    return bbox_targets, bbox_inside_weights
예제 #2
0
파일: roi.py 프로젝트: Kairobo/FastMaskRCNN
def _compute_targets(ex_rois, gt_rois, labels, num_classes):
  """
  This function expands those targets into the 4-of-4*K representation used
  by the network (i.e. only one class has non-zero targets).
  
  Returns:
    bbox_target (ndarray): N x 4K blob of regression targets
    bbox_inside_weights (ndarray): N x 4K blob of loss weights
  """

  assert ex_rois.shape[0] == gt_rois.shape[0]
  assert ex_rois.shape[1] == 4
  assert gt_rois.shape[1] == 4

  targets = bbox_transform(ex_rois, gt_rois)

  clss = labels
  bbox_targets = np.zeros((clss.size, 4 * num_classes), dtype=np.float32)
  bbox_inside_weights = np.zeros(bbox_targets.shape, dtype=np.float32)
  inds = np.where(clss > 0)[0]
  for ind in inds:
    cls = int(clss[ind])
    start = 4 * cls
    end = start + 4
    bbox_targets[ind, start:end] = targets[ind, 0:4]
    bbox_inside_weights[ind, start:end] = 1
  return bbox_targets, bbox_inside_weights
예제 #3
0
def _compute_targets(ex_rois, gt_rois):
  """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] == 5

  return bbox_transform(ex_rois, gt_rois[:, :4]).astype(np.float32, copy=False)
예제 #4
0
def _compute_targets(ex_rois, gt_rois):
    """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] == 5

    if cfg.rpn_box_encoding == 'linear':
        return bbox_transform.bbox_transform_linear(
            ex_rois, gt_rois[:, :4]).astype(np.float32, copy=False)
    if cfg.rpn_box_encoding == 'fastrcnn':
        return bbox_transform.bbox_transform(ex_rois,
                                             gt_rois[:, :4]).astype(np.float32,
                                                                    copy=False)