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


Python cython_nms.nms方法代码示例

本文整理汇总了Python中utils.cython_nms.nms方法的典型用法代码示例。如果您正苦于以下问题:Python cython_nms.nms方法的具体用法?Python cython_nms.nms怎么用?Python cython_nms.nms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.cython_nms的用法示例。


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

示例1: apply_nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def apply_nms(all_boxes, thresh):
    """Apply non-maximum suppression to all predicted boxes output by the
    test_net method.
    """
    num_classes = len(all_boxes)
    num_images = len(all_boxes[0])
    nms_boxes = [[[] for _ in xrange(num_images)]
                 for _ in xrange(num_classes)]
    for cls_ind in xrange(num_classes):
        for im_ind in xrange(num_images):
            dets = all_boxes[cls_ind][im_ind]
            if dets == []:
                continue
            keep = nms(dets, thresh)
            if len(keep) == 0:
                continue
            nms_boxes[cls_ind][im_ind] = dets[keep, :].copy()
    return nms_boxes 
开发者ID:ppengtang,项目名称:dpl,代码行数:20,代码来源:test.py

示例2: apply_nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def apply_nms(all_boxes, thresh):
  """Apply non-maximum suppression to all predicted boxes output by the
  test_net method.
  """
  num_classes = len(all_boxes)
  num_images = len(all_boxes[0])
  nms_boxes = [[[] for _ in range(num_images)] for _ in range(num_classes)]
  for cls_ind in range(num_classes):
    for im_ind in range(num_images):
      dets = all_boxes[cls_ind][im_ind]
      if dets == []:
        continue

      x1 = dets[:, 0]
      y1 = dets[:, 1]
      x2 = dets[:, 2]
      y2 = dets[:, 3]
      scores = dets[:, 4]
      inds = np.where((x2 > x1) & (y2 > y1) & (scores > cfg.TEST.DET_THRESHOLD))[0]
      dets = dets[inds,:]
      if dets == []:
        continue

      keep = nms(dets, thresh)
      if len(keep) == 0:
        continue
      nms_boxes[cls_ind][im_ind] = dets[keep, :].copy()
  return nms_boxes 
开发者ID:pengzhou1108,项目名称:RGB-N,代码行数:30,代码来源:test.py

示例3: nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def nms(dets, thresh):
    """Apply classic DPM-style greedy NMS."""
    if dets.shape[0] == 0:
        return []
    return cython_nms.nms(dets, thresh) 
开发者ID:roytseng-tw,项目名称:Detectron.pytorch,代码行数:7,代码来源:boxes.py

示例4: apply_nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def apply_nms(all_boxes, thresh):
    """Apply non-maximum suppression to all predicted boxes output by the
    test_net method.
    """
    num_classes = len(all_boxes)
    num_images = len(all_boxes[0])
    nms_boxes = [[[] for _ in xrange(num_images)]
                 for _ in xrange(num_classes)]
    for cls_ind in xrange(num_classes):
        for im_ind in xrange(num_images):
            dets = all_boxes[cls_ind][im_ind]
            if dets == []:
                continue

            x1 = dets[:, 0]
            y1 = dets[:, 1]
            x2 = dets[:, 2]
            y2 = dets[:, 3]
            scores = dets[:, 4]
            inds = np.where((x2 > x1) & (y2 > y1) & (scores > cfg.TEST.DET_THRESHOLD))[0]
            dets = dets[inds,:]
            if dets == []:
                continue

            keep = nms(dets, thresh)
            if len(keep) == 0:
                continue
            nms_boxes[cls_ind][im_ind] = dets[keep, :].copy()
    return nms_boxes 
开发者ID:chenwuperth,项目名称:rgz_rcnn,代码行数:31,代码来源:test.py

示例5: demo

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def demo(net, image_name, classes):
    """Detect object classes in an image using pre-computed object proposals."""

    # Load pre-computed Selected Search object proposals
    box_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo',
                            image_name + '_boxes.mat')
    obj_proposals = sio.loadmat(box_file)['boxes']

    # Load the demo image
    im_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo', image_name + '.jpg')
    im = cv2.imread(im_file)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(net, im, obj_proposals, len(classes))
    timer.toc()
    print ('Detection took {:.3f}s for '
           '{:d} object proposals').format(timer.total_time, boxes.shape[0])

    # Visualize detections for each class
    CONF_THRESH = 0.8
    NMS_THRESH = 0.3
    for cls in classes:
        cls_ind = CLASSES.index(cls)
        cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack((cls_boxes,
                          cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, NMS_THRESH)
        dets = dets[keep, :]
        print 'All {} detections with p({} | box) >= {:.1f}'.format(cls, cls,
                                                                    CONF_THRESH)
        vis_detections(im, cls, dets, thresh=CONF_THRESH) 
开发者ID:tanshen,项目名称:SubCNN,代码行数:36,代码来源:demo.py

示例6: nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def nms(dets, thresh):
    import utils.cython_nms as cython_nms

    """Apply classic DPM-style greedy NMS."""
    if dets.shape[0] == 0:
        return []
    return cython_nms.nms(dets, thresh) 
开发者ID:gangadhar-p,项目名称:NucleiDetectron,代码行数:9,代码来源:boxes.py

示例7: nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def nms(dets, thresh, soft_nms=False):
    """Dispatch to either CPU or GPU NMS implementations."""

    if dets.shape[0] == 0:
        return []
    if dets.shape[1] > 5:  # normal box is (x, y, x, y, score), so 5-dim
        return tube_nms(dets, thresh)
    else:
        return cpu_nms(dets, thresh) 
开发者ID:facebookresearch,项目名称:DetectAndTrack,代码行数:11,代码来源:nms_wrapper.py

示例8: traditional_nms

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def traditional_nms(self, boxes, masks, scores, iou_threshold=0.5, conf_thresh=0.05):
        import pyximport
        pyximport.install(setup_args={"include_dirs":np.get_include()}, reload_support=True)

        from utils.cython_nms import nms as cnms

        num_classes = scores.size(0)

        idx_lst = []
        cls_lst = []
        scr_lst = []

        # Multiplying by max_size is necessary because of how cnms computes its area and intersections
        boxes = boxes * cfg.max_size

        for _cls in range(num_classes):
            cls_scores = scores[_cls, :]
            conf_mask = cls_scores > conf_thresh
            idx = torch.arange(cls_scores.size(0), device=boxes.device)

            cls_scores = cls_scores[conf_mask]
            idx = idx[conf_mask]

            if cls_scores.size(0) == 0:
                continue
            
            preds = torch.cat([boxes[conf_mask], cls_scores[:, None]], dim=1).cpu().numpy()
            keep = cnms(preds, iou_threshold)
            keep = torch.Tensor(keep, device=boxes.device).long()

            idx_lst.append(idx[keep])
            cls_lst.append(keep * 0 + _cls)
            scr_lst.append(cls_scores[keep])
        
        idx     = torch.cat(idx_lst, dim=0)
        classes = torch.cat(cls_lst, dim=0)
        scores  = torch.cat(scr_lst, dim=0)

        scores, idx2 = scores.sort(0, descending=True)
        idx2 = idx2[:cfg.max_num_detections]
        scores = scores[:cfg.max_num_detections]

        idx = idx[idx2]
        classes = classes[idx2]

        # Undo the multiplication above
        return boxes[idx] / cfg.max_size, masks[idx], classes, scores 
开发者ID:dbolya,项目名称:yolact,代码行数:49,代码来源:detection.py

示例9: test_net

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def test_net(sess, net, imdb, weights_filename, max_per_image=100, thresh=0.0):
  np.random.seed(cfg.RNG_SEED)
  """Test a Fast R-CNN network on an image database."""
  num_images = len(imdb.image_index)
  # all detections are collected into:
  #  all_boxes[cls][image] = N x 5 array of detections in
  #  (x1, y1, x2, y2, score)
  all_boxes = [[[] for _ in range(num_images)]
         for _ in range(imdb.num_classes)]

  output_dir = get_output_dir(imdb, weights_filename)
  if os.path.isfile(os.path.join(output_dir, 'detections.pkl')):
    all_boxes=pickle.load(open(os.path.join(output_dir, 'detections.pkl'),'r'))
  else:  
    # timers
    _t = {'im_detect' : Timer(), 'misc' : Timer()}

    for i in range(num_images):
      im = cv2.imread(imdb.image_path_at(i))

      _t['im_detect'].tic()
      scores, boxes,_ ,_ = im_detect(sess, net, im)
      _t['im_detect'].toc()

      _t['misc'].tic()

      # skip j = 0, because it's the background class
      for j in range(1, imdb.num_classes):
        inds = np.where(scores[:, j] > thresh)[0]
        cls_scores = scores[inds, j]
        cls_boxes = boxes[inds, j*4:(j+1)*4]
        cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
          .astype(np.float32, copy=False)
        keep = nms(cls_dets, cfg.TEST.NMS)
        cls_dets = cls_dets[keep, :]
        all_boxes[j][i] = cls_dets

      # Limit to max_per_image detections *over all classes*
      if max_per_image > 0:
        image_scores = np.hstack([all_boxes[j][i][:, -1]
                      for j in range(1, imdb.num_classes)])
        if len(image_scores) > max_per_image:
          image_thresh = np.sort(image_scores)[-max_per_image]
          for j in range(1, imdb.num_classes):
            keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
            all_boxes[j][i] = all_boxes[j][i][keep, :]
      _t['misc'].toc()

      print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
          .format(i + 1, num_images, _t['im_detect'].average_time,
              _t['misc'].average_time))

    det_file = os.path.join(output_dir, 'detections_{:f}.pkl'.format(10))
    with open(det_file, 'wb') as f:
      pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)

  print('Evaluating detections')
  imdb.evaluate_detections(all_boxes, output_dir) 
开发者ID:pengzhou1108,项目名称:RGB-N,代码行数:60,代码来源:test.py

示例10: demo

# 需要导入模块: from utils import cython_nms [as 别名]
# 或者: from utils.cython_nms import nms [as 别名]
def demo(sess, net, image_name,bbox):
    """Detect object classes in an image using pre-computed object proposals."""

    # Load the demo image
    #im_file = os.path.join(cfg.DATA_DIR, 'demo', image_name)
    if os.path.isfile(os.path.join(data_dir, image_name)):
        im_file = os.path.join(data_dir, image_name)

    else:
        im_file = os.path.join(data_dir_2, image_name)
    revise=40
    im = cv2.imread(im_file) 
    pixel_means=np.array([[[102, 115, 122]]])

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    try:
        scores, boxes,_,_ = im_detect(sess, net, im)
    except Exception as e:
        print(e)
        return
    timer.toc()
    print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time, boxes.shape[0]))

    # Visualize detections for each class
    CONF_THRESH = 0.0
    NMS_THRESH = 1.0
    
    for cls_ind, cls in enumerate(CLASSES[1:]):
        if cls=='authentic':
            continue
        cls_ind += 1 # because we skipped background

        cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack((cls_boxes,
                          cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, NMS_THRESH)
        dets = dets[keep, :]
        im_score=vis_detections(im, cls, dets,image_name, thresh=CONF_THRESH)
    return im_score 
开发者ID:pengzhou1108,项目名称:RGB-N,代码行数:44,代码来源:demo.py


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