当前位置: 首页>>代码示例>>Python>>正文


Python cython_bbox.bbox_overlaps函数代码示例

本文整理汇总了Python中utils.cython_bbox.bbox_overlaps函数的典型用法代码示例。如果您正苦于以下问题:Python bbox_overlaps函数的具体用法?Python bbox_overlaps怎么用?Python bbox_overlaps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bbox_overlaps函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _compute_targets

def _compute_targets(gt_rois, ex_rois):
    """Compute bounding-box regression targets for an image.
        gt_rois: ground truth rois
        ex_rois: example rois
    """
    K = ex_rois.shape[0]
    N = gt_rois.shape[0]
    # Ensure ROIs are floats
    gt_rois = gt_rois.astype(np.float, copy=False)
    ex_rois = ex_rois.astype(np.float, copy=False)

    # bbox targets: (x1,y1,x2,y2,ex_rois_ind,subreg_ind)  
    targets = np.zeros((0, 7), dtype=np.float32)
    
    if K == 0 or N == 0:
        return targets
    
    # For each region, find out objects that are adjacent
    # Match objects to sub-regions with maximum overlaps. 
    # Objects with large overlaps with any sub-regions are given priority.
    overlaps = bbox_overlaps(ex_rois, gt_rois)
    max_overlaps = overlaps.max(axis=1)

    for k in xrange(K):
        
        if max_overlaps[k] < cfg.SEAR.ADJ_THRESH:
            continue
        
        re = ex_rois[k, :]
        L = np.array([[re[2]-re[0], re[3]-re[1], re[2]-re[0], re[3]-re[1]]]) 
        delta = np.array([[re[0], re[1], re[0], re[1]]])
        # sub-regions`
        s_re = (L * cfg.SEAR.SUBREGION) + delta
        s_re = s_re.astype(np.float, copy=False)
        # compute the overlaps between sub-regions and each objects
        sre_gt_overlaps = bbox_overlaps(s_re, gt_rois)
        # find out the objects that are actually adjacent
        adj_th = (sre_gt_overlaps[0] >= cfg.SEAR.ADJ_THRESH)
        match_inds = np.where(adj_th)[0]
        sre_gt_overlaps[:, ~adj_th] = -1
#        adj_th = (sre_gt_overlaps >= cfg.SEAR.ADJ_THRESH)
#        match_inds = np.where(np.any(adj_th, axis=0))[0]
        if match_inds.shape[0]>0:    # there is object to match
            for _ in xrange(min(cfg.SEAR.NUM_SUBREG, match_inds.shape[0])):            
                reg_idx, gt_idx = np.unravel_index(sre_gt_overlaps.argmax(), 
                                                   sre_gt_overlaps.shape)
                
                # no more valid match
#                if sre_gt_overlaps[reg_idx, gt_idx] < cfg.SEAR.ADJ_THRESH:
#                    break
                t_ki = _compute_bbox_deltas(ex_rois[[k], :],
                                            gt_rois[[gt_idx], :])                
                new_target = np.hstack((t_ki, np.array([[k, reg_idx, overlaps[k, gt_idx]]])))
                targets = np.vstack((targets, new_target))                

                sre_gt_overlaps[reg_idx, :] = -1
                sre_gt_overlaps[:, gt_idx] = -1

    return targets
开发者ID:baiyancheng20,项目名称:az-net,代码行数:59,代码来源:roidb.py

示例2: _sample_rois

def _sample_rois(all_rois, gt_boxes, fg_rois_per_image, rois_per_image, num_classes, dontcare):
    """Generate a random sample of RoIs comprising foreground and background
    examples.
    """
    # overlaps: (rois x gt_boxes)
    overlaps = bbox_overlaps(
        np.ascontiguousarray(all_rois[:, 1:5], dtype=np.float),
        np.ascontiguousarray(gt_boxes[:, :4], dtype=np.float))
    gt_assignment = overlaps.argmax(axis=1)
    max_overlaps = overlaps.max(axis=1)
    labels = gt_boxes[gt_assignment, 4]

    # Select foreground RoIs as those with >= FG_THRESH overlap
    fg_inds = np.where(max_overlaps >= cfg.TRAIN.FG_THRESH)[0]
    # Guard against the case when an image has fewer than fg_rois_per_image
    # foreground RoIs
    fg_rois_per_this_image = min(fg_rois_per_image, fg_inds.size)
    # Sample foreground regions without replacement
    if fg_inds.size > 0:
        fg_inds = npr.choice(fg_inds, size=fg_rois_per_this_image, replace=False)

    # Select background RoIs as those within [BG_THRESH_LO, BG_THRESH_HI)
    bg_inds = np.where((max_overlaps < cfg.TRAIN.BG_THRESH_HI) &
                       (max_overlaps >= cfg.TRAIN.BG_THRESH_LO))[0]
    
    # rm dontcare in bg_inds
    if dontcare.size != 0:
        overlaps = bbox_overlaps(
            np.ascontiguousarray(all_rois[bg_inds, 1:5], dtype=np.float),
            np.ascontiguousarray(dontcare, dtype=np.float))
        max_overlaps = overlaps.max(axis=1)
        rm_inds=np.where(max_overlaps < cfg.TRAIN.FG_THRESH)[0]
        bg_inds = np.array([bg_inds[i] for i in rm_inds],dtype=np.int)
    
    # Compute number of background RoIs to take from this image (guarding
    # against there being fewer than desired)
    bg_rois_per_this_image = rois_per_image - fg_rois_per_this_image
    bg_rois_per_this_image = min(bg_rois_per_this_image, bg_inds.size)
    # Sample background regions without replacement
    if bg_inds.size > 0:
        bg_inds = npr.choice(bg_inds, size=bg_rois_per_this_image, replace=False)
    #print 'bg_inds size = %d'%bg_inds.size
    # The indices that we're selecting (both fg and bg)
    keep_inds = np.append(fg_inds, bg_inds)
    
    # Select sampled values from various arrays:
    labels = labels[keep_inds]
    # Clamp labels for the background RoIs to 0
    labels[fg_rois_per_this_image:] = 0
    rois = all_rois[keep_inds]

    bbox_target_data = _compute_targets(
        rois[:, 1:5], gt_boxes[gt_assignment[keep_inds], :4], labels)

    bbox_targets, bbox_inside_weights = \
        _get_bbox_regression_labels(bbox_target_data, num_classes)

    return labels, rois, bbox_targets, bbox_inside_weights
开发者ID:guoshouyan,项目名称:faster-rcnn-car,代码行数:58,代码来源:proposal_target_layer.py

示例3: extract_pos_and_neg_feat

    def extract_pos_and_neg_feat(self):
        # extract positive features
        pos = {}
        neg = np.zeros([50000, 4096])
        for i in range(20):
            pos[i] = np.zeros([0, 4096])
        neg_cnt = 0
        for i in range(len(self.imdb.image_index)):
            print(str(i) + " "),
            data = sio.loadmat(os.path.join(self.DATA_ROOT_PATH, 
                self.imdb.image_index[i]))
            boxes = data['boxes']
            feat = data['feat']
            black_list = []
            gt_boxes   = gts['boxes'][0][i]
            gt_classes = gts['class'][0][i]
            overlaps = bbox_overlaps(gt_boxes.astype(np.float),
                    boxes.astype(np.float))
            for idx, gt_box in enumerate(gt_boxes):
                for j in range(boxes.shape[0]):
                    box = boxes[j,:] # [x1 y1 x2 y2]
                    if overlaps[idx, j] > 0.5:
                        cls = gt_classes[idx][0] - 1
                        pos[cls] = np.row_stack([pos[cls], feat[j,:]]) 
                    if overlaps[idx, j] > 0.2:
                        black_list.append(idx)

            if neg_cnt < neg.shape[0]:
                cand = set(range(feat.shape[0])) - set(black_list)
                rndidx = np.random.permutation(range(len(cand)))[0:50]
                negidx = np.array(list(cand))[rndidx]
                neg_feat = feat[negidx, :]
                neg[neg_cnt:neg_cnt+50] = neg_feat

        return pos
开发者ID:rhina,项目名称:web_obret,代码行数:35,代码来源:preset.py

示例4: _sample_rois

def _sample_rois(all_rois, gt_boxes, fg_rois_per_image, rois_per_image, num_classes,sample_type='fpn', k0 = 4):
    """Generate a random sample of RoIs comprising foreground and background
    examples.
    """
    # overlaps: (rois x gt_boxes)
    overlaps = bbox_overlaps(
        np.ascontiguousarray(all_rois[:, 1:5], dtype=np.float),
        np.ascontiguousarray(gt_boxes[:, :4], dtype=np.float))
    gt_assignment = overlaps.argmax(axis=1)
    max_overlaps = overlaps.max(axis=1)
    labels = gt_boxes[gt_assignment, 4]

    # Select foreground RoIs as those with >= FG_THRESH overlap
    fg_inds = np.where(max_overlaps >= cfg.TRAIN.FG_THRESH)[0]
    # Guard against the case when an image has fewer than fg_rois_per_image
    # foreground RoIs
    fg_rois_per_this_image = min(fg_rois_per_image, fg_inds.size)
    # Sample foreground regions without replacement
    if fg_inds.size > 0:
        fg_inds = npr.choice(fg_inds, size=fg_rois_per_this_image, replace=False)

    # Select background RoIs as those within [BG_THRESH_LO, BG_THRESH_HI)
    bg_inds = np.where((max_overlaps < cfg.TRAIN.BG_THRESH_HI) &
                       (max_overlaps >= cfg.TRAIN.BG_THRESH_LO))[0]
    # Compute number of background RoIs to take from this image (guarding
    # against there being fewer than desired)
    bg_rois_per_this_image = rois_per_image - fg_rois_per_this_image
    bg_rois_per_this_image = min(bg_rois_per_this_image, bg_inds.size)
    # Sample background regions without replacement
    if bg_inds.size > 0:
        bg_inds = npr.choice(bg_inds, size=bg_rois_per_this_image, replace=False)

    # The indices that we're selecting (both fg and bg)
    keep_inds = np.append(fg_inds, bg_inds)
    # Select sampled values from various arrays:
    labels = labels[keep_inds]
    # Clamp labels for the background RoIs to 0
    labels[fg_rois_per_this_image:] = 0
    rois = all_rois[keep_inds]

    bbox_target_data = _compute_targets(
        rois[:, 1:5], gt_boxes[gt_assignment[keep_inds], :4], labels)

    bbox_targets, bbox_inside_weights = \
        _get_bbox_regression_labels(bbox_target_data, num_classes)

    if sample_type == 'fpn':
        #print 0
        w = (rois[:,3]-rois[:,1])
        h = (rois[:,4]-rois[:,2])
        s = w * h
        s[s<=0]=1e-6
        layer_index = np.floor(k0+np.log2(np.sqrt(s)/224))

        layer_index[layer_index<2]=2
        layer_index[layer_index>5]=5
        #print 1
        return rois, labels, bbox_targets, bbox_inside_weights, layer_index #rois:[512,5]   labels:[512,]
    else:
        return rois, labels, bbox_targets, bbox_inside_weights
开发者ID:attendfov,项目名称:FPN-1,代码行数:60,代码来源:proposal_target_layer.py

示例5: create_roidb_from_box_list

    def create_roidb_from_box_list(self, box_list, gt_roidb):
        assert len(box_list) == self.num_images, \
                'Number of boxes must match number of ground-truth images'
        roidb = []
        for i in xrange(self.num_images):
            boxes = box_list[i]
            num_boxes = boxes.shape[0]
            overlaps = np.zeros((num_boxes, self.num_classes), dtype=np.float32)

            if gt_roidb is not None and gt_roidb[i]['boxes'].size > 0:
                gt_boxes = gt_roidb[i]['boxes']
                gt_classes = gt_roidb[i]['gt_classes']
                gt_overlaps = bbox_overlaps(boxes.astype(np.float),
                                            gt_boxes.astype(np.float))
                argmaxes = gt_overlaps.argmax(axis=1)
                maxes = gt_overlaps.max(axis=1)
                I = np.where(maxes > 0)[0]
                overlaps[I, gt_classes[argmaxes[I]]] = maxes[I]

            overlaps = scipy.sparse.csr_matrix(overlaps)
            roidb.append({
                'boxes' : boxes,
                'gt_classes' : np.zeros((num_boxes,), dtype=np.int32),
                'gt_overlaps' : overlaps,
                'flipped' : False,
                'seg_areas' : np.zeros((num_boxes,), dtype=np.float32),
            })
        return roidb
开发者ID:shls,项目名称:py-faster-rcnn,代码行数:28,代码来源:imdb.py

示例6: _compute_targets

def _compute_targets(rois, overlaps, labels):
    """Compute bounding-box regression targets for an image."""
    # Indices of ground-truth ROIs
    gt_inds = np.where(overlaps == 1)[0]
    if len(gt_inds) == 0:
        # Bail if the image has no ground-truth ROIs
        return np.zeros((rois.shape[0], 5), dtype=np.float32)
    # 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 = bbox_overlaps(
        np.ascontiguousarray(rois[ex_inds, :], dtype=np.float),
        np.ascontiguousarray(rois[gt_inds, :], dtype=np.float))

    # 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, :]

    targets = np.zeros((rois.shape[0], 5), dtype=np.float32)
    targets[ex_inds, 0] = labels[ex_inds]
    targets[ex_inds, 1:] = bbox_transform(ex_rois, gt_rois)
    return targets
开发者ID:minimrbanana,项目名称:py-faster-rcnn-train,代码行数:25,代码来源:roidb.py

示例7: create_roidb_from_box_list

    def create_roidb_from_box_list(self, box_list, gt_roidb):
        assert len(box_list) == self.num_images, \
                'Number of boxes must match number of ground-truth images. %s vs. %s' % (len(box_list), self.num_images)
        roidb = []
        print 'create_roidb_from_box_list() start'
        for i in xrange(self.num_images):
            max_proposal_box = cfg.MAX_PROPOSAL_NO
            boxes = box_list[i][:max_proposal_box]
            num_boxes = boxes.shape[0]
            overlaps = np.zeros((num_boxes, self.num_classes), dtype=np.float32)

            if gt_roidb is not None:
                gt_boxes = gt_roidb[i]['gt_boxes']
                gt_classes = gt_roidb[i]['gt_classes']
                gt_overlaps = bbox_overlaps(boxes.astype(np.float),
                                            gt_boxes.astype(np.float))
                argmaxes = gt_overlaps.argmax(axis=1)
                maxes = gt_overlaps.max(axis=1)
                I = np.where(maxes > 0)[0]
                overlaps[I, gt_classes[argmaxes[I]]] = maxes[I]

            overlaps = scipy.sparse.csr_matrix(overlaps)
            roidb.append({'boxes' : boxes,
                          'gt_classes' : np.zeros((num_boxes,),
                                                  dtype=np.int32),
                          'gt_overlaps' : overlaps,
                          'flipped' : False})
        print 'create_roidb_from_box_list() end'
        return roidb
开发者ID:only4hj,项目名称:fast-rcnn,代码行数:29,代码来源:imdb.py

示例8: _anchor_target_layer

def _anchor_target_layer(anchors, gt_boxes, im_info, feat_stride, num_anchors, rpn_cls_score):
    height, width = rpn_cls_score.shape[1:3]
    indexs = np.where((anchors[:, 0] > 0) &
                      (anchors[:, 1] > 0) &
                      (anchors[:, 2] < width*feat_stride) &
                      (anchors[:, 3] < height*feat_stride))[0]
    inside_anchors = anchors[indexs]

    labels = np.zeros((len(indexs),), dtype=np.float32)
    labels.fill(-1)

    # overlaps between the anchors and the gt boxes
    # overlaps (ex, gt)
    overlaps = bbox_overlaps(
        np.ascontiguousarray(inside_anchors, dtype=np.float),
        np.ascontiguousarray(gt_boxes, dtype=np.float))
    arg_max_overlaps = np.argmax(overlaps, axis=1)
    max_overlaps = overlaps[np.arange(overlaps.shape[0]), arg_max_overlaps]
    gt_arg_max_overlaps = np.argmax(overlaps, axis=0)
    gt_max_overlaps = overlaps[gt_arg_max_overlaps, np.arange(overlaps.shape[1])]

    gt_arg_max_overlaps = np.where(overlaps == gt_max_overlaps)

    labels[max_overlaps < 0.3] = 0
    labels[gt_arg_max_overlaps] = 1
    labels[max_overlaps > 0.7] = 1
开发者ID:jacke121,项目名称:tf_rfcn,代码行数:26,代码来源:_proposal_layers.py

示例9: create_roidb_from_box_list

    def create_roidb_from_box_list(self, box_list, gt_roidb):
        assert len(box_list) == self.num_images, "Number of boxes must match number of ground-truth images"
        roidb = []
        for i in xrange(self.num_images):
            boxes = box_list[i]
            num_boxes = boxes.shape[0]
            overlaps = np.zeros((num_boxes, self.num_classes), dtype=np.float32)

            if gt_roidb is not None:
                gt_boxes = gt_roidb[i]["boxes"]
                gt_classes = gt_roidb[i]["gt_classes"]
                gt_overlaps = bbox_overlaps(boxes.astype(np.float), gt_boxes.astype(np.float))
                if gt_overlaps.shape[1] > 0:
                    argmaxes = gt_overlaps.argmax(axis=1)
                    maxes = gt_overlaps.max(axis=1)
                    I = np.where(maxes > 0)[0]
                    overlaps[I, gt_classes[argmaxes[I]]] = maxes[I]
                else:
                    overlaps = np.zeros((num_boxes, self.num_classes), dtype=np.float32)

            overlaps = scipy.sparse.csr_matrix(overlaps)
            roidb.append(
                {
                    "boxes": boxes,
                    "gt_classes": np.zeros((num_boxes,), dtype=np.int32),
                    "gt_overlaps": overlaps,
                    "flipped": False,
                }
            )
        return roidb
开发者ID:xiaolonw,项目名称:fast-rcnn-distillation,代码行数:30,代码来源:imdb.py

示例10: _sample_rois

def _sample_rois(all_rois, all_scores, gt_boxes, fg_rois_per_image, rois_per_image, num_classes):
  """Generate a random sample of RoIs comprising foreground and background
  examples.
  """
  # overlaps: (rois x gt_boxes)
  overlaps = bbox_overlaps(
    np.ascontiguousarray(all_rois[:, 1:5], dtype=np.float),
    np.ascontiguousarray(gt_boxes[:, :4], dtype=np.float))
  gt_assignment = overlaps.argmax(axis=1)
  max_overlaps = overlaps.max(axis=1)
  if cfg.FRAME_REG:
    labels = gt_boxes[gt_assignment, 12]
  else:
    labels = gt_boxes[gt_assignment, 4]
  # Select foreground RoIs as those with >= FG_THRESH overlap
  fg_inds = np.where(max_overlaps >= cfg.TRAIN.FG_THRESH)[0]
  # Guard against the case when an image has fewer than fg_rois_per_image
  # Select background RoIs as those within [BG_THRESH_LO, BG_THRESH_HI)
  bg_inds = np.where((max_overlaps < cfg.TRAIN.BG_THRESH_HI) &
                     (max_overlaps >= cfg.TRAIN.BG_THRESH_LO))[0]

  # Small modification to the original version where we ensure a fixed number of regions are sampled
  if fg_inds.size > 0 and bg_inds.size > 0:
    fg_rois_per_image = min(fg_rois_per_image, fg_inds.size)
    fg_inds = npr.choice(fg_inds, size=int(fg_rois_per_image), replace=False)
    bg_rois_per_image = rois_per_image - fg_rois_per_image
    to_replace = bg_inds.size < bg_rois_per_image
    bg_inds = npr.choice(bg_inds, size=int(bg_rois_per_image), replace=to_replace)
  elif fg_inds.size > 0:
    to_replace = fg_inds.size < rois_per_image
    fg_inds = npr.choice(fg_inds, size=int(rois_per_image), replace=to_replace)
    fg_rois_per_image = rois_per_image
  elif bg_inds.size > 0:
    to_replace = bg_inds.size < rois_per_image
    bg_inds = npr.choice(bg_inds, size=int(rois_per_image), replace=to_replace)
    fg_rois_per_image = 0
  else:
    import pdb
    pdb.set_trace()

  # The indices that we're selecting (both fg and bg)
  keep_inds = np.append(fg_inds, bg_inds)
  # Select sampled values from various arrays:
  labels = labels[keep_inds]
  # Clamp labels for the background RoIs to 0
  labels[int(fg_rois_per_image):] = 0
  rois = all_rois[keep_inds]
  roi_scores = all_scores[keep_inds]
  if cfg.FRAME_REG:
    p = 12
  else:
    p = 4
  bbox_target_data, poly_target_data = _compute_targets(
    rois[:, 1:5], gt_boxes[gt_assignment[keep_inds], :p], labels)

  bbox_targets, bbox_inside_weights, poly_targets, poly_inside_weights = \
    _get_bbox_regression_labels(bbox_target_data, poly_target_data, num_classes)
  return labels, rois, roi_scores, bbox_targets, bbox_inside_weights,\
         poly_targets, poly_inside_weights
开发者ID:lz20061213,项目名称:quadrilateral,代码行数:59,代码来源:proposal_target_layer.py

示例11: _sample_rois

def _sample_rois(all_rois, gt_boxes, fg_rois_per_image, rois_per_image, num_classes):#, pose_a, pose_e):
    """Generate a random sample of RoIs comprising foreground and background
    examples.
    """
    # overlaps: (rois x gt_boxes)
    overlaps = bbox_overlaps(
        np.ascontiguousarray(all_rois[:, 1:5], dtype=np.float),
        np.ascontiguousarray(gt_boxes[:, :4], dtype=np.float))
    gt_assignment = overlaps.argmax(axis=1)
    max_overlaps = overlaps.max(axis=1)
    labels = gt_boxes[gt_assignment, 4]
    poses_a = gt_boxes[gt_assignment, 5]
    poses_e = gt_boxes[gt_assignment, 6]
    poses_t = gt_boxes[gt_assignment, 7]
    # Select foreground RoIs as those with >= FG_THRESH overlap
    fg_inds = np.where(max_overlaps >= cfg.TRAIN.FG_THRESH)[0]
    # Guard against the case when an image has fewer than fg_rois_per_image
    # foreground RoIs
    fg_rois_per_this_image = min(fg_rois_per_image, fg_inds.size)
    # Sample foreground regions without replacement
    if fg_inds.size > 0:
        fg_inds = npr.choice(fg_inds, size=fg_rois_per_this_image, replace=False)

    # Select background RoIs as those within [BG_THRESH_LO, BG_THRESH_HI)
    bg_inds = np.where((max_overlaps < cfg.TRAIN.BG_THRESH_HI) &
                       (max_overlaps >= cfg.TRAIN.BG_THRESH_LO))[0]
    # Compute number of background RoIs to take from this image (guarding
    # against there being fewer than desired)
    bg_rois_per_this_image = rois_per_image - fg_rois_per_this_image
    bg_rois_per_this_image = min(bg_rois_per_this_image, bg_inds.size)
    # Sample background regions without replacement
    if bg_inds.size > 0:
        bg_inds = npr.choice(bg_inds, size=bg_rois_per_this_image, replace=False)

    # The indices that we're selecting (both fg and bg)
    keep_inds = np.append(fg_inds, bg_inds)
    # Select sampled values from various arrays:
    labels = labels[keep_inds]
    poses_a = poses_a[keep_inds]
    poses_e = poses_e[keep_inds]
    poses_t = poses_t[keep_inds]
    #for p in xrange(int(fg_rois_per_this_image)):
    #    labels[p] = (labels[p]-1) * 24 + poses_a[p]+1 
    # Clamp labels for the background RoIs to 0
    labels[fg_rois_per_this_image:] = 0
    poses_a[fg_rois_per_this_image:] = -1
    poses_e[fg_rois_per_this_image:] = -1
    poses_t[fg_rois_per_this_image:] = -1
    rois = all_rois[keep_inds]
    print zip(labels,poses_a)
    #pose_a, pose_e = _get_pose_labels(pose_a, pose_e, len(rois), int(fg_rois_per_this_image))
    bbox_target_data = _compute_targets(
        rois[:, 1:5], gt_boxes[gt_assignment[keep_inds], :4], labels)

    bbox_targets, bbox_inside_weights = _get_bbox_regression_labels(bbox_target_data, num_classes)
    return labels, rois, bbox_targets, bbox_inside_weights, poses_a, poses_e, poses_t
开发者ID:debidatta,项目名称:py-faster-rcnn,代码行数:56,代码来源:proposal_target_layer.py

示例12: calc_precision_recall

def calc_precision_recall(all_boxes, imdb):
    res_num = {'tp': 0, 'gt': 0, 'det': 0, 'bad_case': 0}
    
    # save bad case result 
    bad_case_output_dir = os.path.join(cfg.ROOT_DIR, 'data', 'bad_case_'+imdb.name)
    if not os.path.exists(bad_case_output_dir):
        os.makedirs(bad_case_output_dir)
    else:
        for f in os.listdir(bad_case_output_dir):
            os.remove(os.path.join(bad_case_output_dir, f))

    gt_roidb = imdb.roidb
    outside_pad = 10
    bounding = lambda box, gt_box: np.all((box[:2] <= gt_box[:2] + outside_pad) & 
                                          (box[2:] >= gt_box[2:] - outside_pad))

    for im_i, boxes in enumerate(all_boxes):
        gt_boxes = gt_roidb[im_i]['boxes']
        gt_overlaps = bbox_overlaps(boxes[:,:-1].astype(np.float), 
                                    gt_boxes.astype(np.float))
        argmaxes = gt_overlaps.argmax(axis=1)
        """ 
        maxes = gt_overlaps.max(axis=1)
        tp_inds = np.where(maxes >= 0.7)[0]
        """
        tp_inds = np.zeros((argmaxes.shape[0]), dtype=bool)
        for box_i, box in enumerate(boxes):
            if bounding(box[:-1], gt_boxes[argmaxes[box_i]]):
                tp_inds[box_i] = True

        tp_argmaxes = argmaxes[tp_inds]
        tp_argmaxes = np.unique(tp_argmaxes)
        tp_num = tp_argmaxes.size
        
        res_num['tp'] = res_num['tp'] + tp_num
        res_num['gt'] = res_num['gt'] + len(gt_boxes)
        res_num['det'] = res_num['det'] + len(boxes)

        if tp_num != len(boxes) or tp_num != len(gt_boxes):
            res_num['bad_case'] = res_num['bad_case'] + 1
            img_path = imdb.image_path_at(im_i)
            im = cv2.imread(img_path)
            bad_name = os.path.splitext(os.path.basename(img_path))[0]
            res_im_file = os.path.join(bad_case_output_dir, '{:s}.jpg'.format(bad_name))
            save_detection_res(im, res_im_file, boxes, gt_boxes)
            print 'images: {:d}/{:d}  !!!  BAD CASE'.format(im_i, len(all_boxes))
        else:
            print 'images: {:d}/{:d}'.format(im_i, len(all_boxes))

    print '=' * 20
    print 'final bad case number: {:d}'.format(res_num['bad_case'])
    print 'final precision: {:.3f}, recall: {:.3f}.'.format(
                                        float(res_num['tp'])/float(res_num['det']), 
                                        float(res_num['tp'])/float(res_num['gt']))
    print '=' * 20    
开发者ID:XinGuo1993,项目名称:faster-rcnn_gx,代码行数:55,代码来源:hyh.py

示例13: compare

def compare(name,dets,thresh):
    suppressed=nms_proposal(dets,thresh)
    gt = nms_gt(name)

    overlaps = bbox_overlaps(
            np.ascontiguousarray(dets[:,0:4], dtype=np.float),
            np.ascontiguousarray(gt, dtype=np.float))
    argmax_overlaps = overlaps.argmax(axis=1)
    max_overlaps = overlaps[np.arange(len(overlaps)), argmax_overlaps]
    site = np.where(max_overlaps > 0.5)

    gt_sup=np.array(suppressed)
    gt_sup[site]=(argmax_overlaps[site]+1)*-1
    return suppressed,gt_sup
开发者ID:guoshouyan,项目名称:faster-rcnn-car,代码行数:14,代码来源:nms.py

示例14: _sample_output

    def _sample_output(self, all_rois, gt_boxes, im_scale, gt_masks, mask_info):
        overlaps = bbox_overlaps(
            np.ascontiguousarray(all_rois[:, 1:5], dtype=np.float),
            np.ascontiguousarray(gt_boxes[:, :4], dtype=np.float))
        gt_assignment = overlaps.argmax(axis=1)
        max_overlaps = overlaps.max(axis=1)
        labels = gt_boxes[gt_assignment, 4]
        # Sample foreground indexes
        fg_inds = np.where(max_overlaps >= cfg.TRAIN.BBOX_THRESH)[0]
        bg_inds = np.where(max_overlaps < cfg.TRAIN.BBOX_THRESH)[0]
        keep_inds = np.append(fg_inds, bg_inds).astype(int)
        # Select sampled values from various arrays:
        labels = labels[keep_inds]
        # Clamp labels for the background RoIs to 0
        labels[len(fg_inds):] = 0
        rois = all_rois[keep_inds]

        bbox_target_data = bbox_compute_targets(
            rois[:, 1:5], gt_boxes[gt_assignment[keep_inds], :4], normalize=True)
        bbox_target_data = np.hstack((labels[:, np.newaxis], bbox_target_data))\
            .astype(np.float32, copy=False)
        bbox_targets, bbox_inside_weights = get_bbox_regression_label(
            bbox_target_data, 21)

        scaled_rois = rois[:, 1:5] / float(im_scale)
        scaled_gt_boxes = gt_boxes[:, :4] / float(im_scale)

        pos_masks = np.zeros((len(keep_inds), 1,  cfg.MASK_SIZE,  cfg.MASK_SIZE))
        top_mask_info = np.zeros((len(keep_inds), 12))
        top_mask_info[len(fg_inds):, :] = -1

        for i, val in enumerate(fg_inds):
            gt_box = scaled_gt_boxes[gt_assignment[val]]
            gt_box = np.around(gt_box).astype(int)
            ex_box = np.around(scaled_rois[i]).astype(int)
            gt_mask = gt_masks[gt_assignment[val]]
            gt_mask_info = mask_info[gt_assignment[val]]
            gt_mask = gt_mask[0:gt_mask_info[0], 0:gt_mask_info[1]]
            # regression targets is the intersection of bounding box and gt mask
            ex_mask = intersect_mask(ex_box, gt_box, gt_mask)
            pos_masks[i, ...] = ex_mask
            top_mask_info[i, 0] = gt_assignment[val]
            top_mask_info[i, 1] = gt_mask_info[0]
            top_mask_info[i, 2] = gt_mask_info[1]
            top_mask_info[i, 3] = labels[i]
            top_mask_info[i, 4:8] = ex_box
            top_mask_info[i, 8:12] = gt_box

        return labels, rois, fg_inds, keep_inds, pos_masks, top_mask_info, bbox_targets, bbox_inside_weights
开发者ID:1165048017,项目名称:MNC,代码行数:49,代码来源:stage_bridge_layer.py

示例15: _matched_information

 def _matched_information(self, curr_retrieved, curr_gt):
     is_matched = np.zeros((len(self.all_matched_threshold), 
         len(curr_retrieved)), dtype = np.bool)
     if len(curr_retrieved) == 0 or len(curr_gt) == 0:
         return is_matched 
     else:
         gt_overlaps = bbox_overlaps(curr_retrieved.astype(np.float),
                                     curr_gt.astype(np.float))
         matched_idx = gt_overlaps.argmax(axis = 1)
         for k in range(len(self.all_matched_threshold)):
             matched_threshold = self.all_matched_threshold[k]
             gt_used = np.zeros(len(curr_gt), dtype = np.bool)
             for i, j in enumerate(matched_idx):
                 if gt_overlaps[i, j] >= matched_threshold and \
                         gt_used[j] == False:
                     gt_used[j] = True
                     is_matched[k, i] = True
     return is_matched
开发者ID:shawn-tian,项目名称:fast-rcnn,代码行数:18,代码来源:vi_detection.py


注:本文中的utils.cython_bbox.bbox_overlaps函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。