本文整理汇总了Python中model.nms_wrapper.nms方法的典型用法代码示例。如果您正苦于以下问题:Python nms_wrapper.nms方法的具体用法?Python nms_wrapper.nms怎么用?Python nms_wrapper.nms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.nms_wrapper
的用法示例。
在下文中一共展示了nms_wrapper.nms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: video_demo
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def video_demo(sess, net, image):
# Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
scores, boxes = im_detect(sess, net, image)
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.85
NMS_THRESH = 0.3
inds = np.where(scores[:, 0] > CONF_THRESH)[0]
scores = scores[inds, 0]
boxes = boxes[inds, :]
dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
keep = nms(dets, NMS_THRESH)
dets = dets[keep, :]
return dets
# vis_detections(image, CLASSES[1], dets, thresh=CONF_THRESH)
示例2: run_on_fddb
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def run_on_fddb(sess, net, image_name):
"""Detect object classes in an image using pre-computed object proposals."""
# Load the demo image
im = cv2.imread(image_name)
# Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
scores, boxes = im_detect(sess, net, im)
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.5
NMS_THRESH = 0.3
inds = np.where(scores[:, 0] > CONF_THRESH)[0]
scores = scores[inds, 0]
boxes = boxes[inds, :]
dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
keep = nms(dets, NMS_THRESH)
dets = dets[keep, :]
return dets
示例3: draw_rpn_boxes
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def draw_rpn_boxes(img, img_name, boxes, scores, im_scale, nms, save_dir):
"""
:param boxes: [(x1, y1, x2, y2)]
"""
boxes = recover_scale(boxes, im_scale)
base_name = img_name.split('/')[-1]
color = (0, 255, 0)
out = img.copy()
if nms:
boxes, scores = TextDetector.pre_process(boxes, scores)
file_name = "%s_rpn_nms.jpg" % base_name
else:
file_name = "%s_rpn.jpg" % base_name
for i, box in enumerate(boxes):
cv2.rectangle(out, (box[0], box[1]), (box[2], box[3]), color, 2)
cx = int((box[0] + box[2]) / 2)
cy = int((box[1] + box[3]) / 2)
cv2.putText(out, "%.01f" % scores[i], (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.2, (255, 0, 0))
cv2.imwrite(os.path.join(save_dir, file_name), out)
示例4: proposal_layer_combine_rpn
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def proposal_layer_combine_rpn(proposals, scores, cfg_key):
"""Only for evluation on RPN stage
"""
assert (cfg_key == 'TEST')
if type(cfg_key) == bytes:
cfg_key = cfg_key.decode('utf-8')
nms_thresh = cfg[cfg_key].RPN_NMS_THRESH
post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
order = scores.ravel().argsort()[::-1]
proposals = proposals[order, :]
scores = scores[order]
# Non-maximal suppression
keep = nms(np.hstack((proposals[:, 1:], scores)), nms_thresh)
# Pick th top region proposals after NMS
if post_nms_topN < len(keep):
keep = keep[:post_nms_topN]
proposals = proposals[keep, :]
scores = scores[keep]
if cfg.VERBOSE:
print('PROPOSAL layer. proposals:', scores.size)
return proposals, scores
示例5: demo
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def demo(sess, net, image_name):
"""Detect pedestrians in an image using pre-computed model."""
# Load the demo image
im1_file = os.path.join(cfg.DATA_DIR, 'demo', image_name + '_visible.png')
im1 = cv2.imread(im1_file)
im2_file = os.path.join(cfg.DATA_DIR, 'demo', image_name + '_lwir.png')
im2 = cv2.imread(im2_file)
im = [im1, im2]
# Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
boxes, scores = im_detect_demo(sess, net, im)
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.5
NMS_THRESH = 0.3
dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
keep = nms(dets, NMS_THRESH)
dets = dets[keep, :]
vis_detections(im, dets, thresh=CONF_THRESH)
示例6: apply_nms
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper 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))[0]
dets = dets[inds,:]
if dets == []:
continue
keep = nms(torch.from_numpy(dets), thresh).numpy()
if len(keep) == 0:
continue
nms_boxes[cls_ind][im_ind] = dets[keep, :].copy()
return nms_boxes
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:30,代码来源:test.py
示例7: proposal_layer
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def proposal_layer(rpn_cls_prob, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchors, num_anchors):
"""A simplified version compared to fast/er RCNN
For details please see the technical report
"""
if type(cfg_key) == bytes:
cfg_key = cfg_key.decode('utf-8')
pre_nms_topN = cfg[cfg_key].RPN_PRE_NMS_TOP_N
post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
nms_thresh = cfg[cfg_key].RPN_NMS_THRESH
# Get the scores and bounding boxes
scores = rpn_cls_prob[:, :, :, num_anchors:]
rpn_bbox_pred = rpn_bbox_pred.view((-1, 4))
scores = scores.contiguous().view(-1, 1)
proposals = bbox_transform_inv(anchors, rpn_bbox_pred)
proposals = clip_boxes(proposals, im_info[:2])
# Pick the top region proposals
scores, order = scores.view(-1).sort(descending=True)
if pre_nms_topN > 0:
order = order[:pre_nms_topN]
scores = scores[:pre_nms_topN].view(-1, 1)
proposals = proposals[order.data, :]
# Non-maximal suppression
keep = nms(torch.cat((proposals, scores), 1).data, nms_thresh)
# Pick th top region proposals after NMS
if post_nms_topN > 0:
keep = keep[:post_nms_topN]
proposals = proposals[keep, :]
scores = scores[keep,]
# Only support single image as input
batch_inds = Variable(proposals.data.new(proposals.size(0), 1).zero_())
blob = torch.cat((batch_inds, proposals), 1)
return blob, scores
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:40,代码来源:proposal_layer.py
示例8: generate_pseudo_gtbox
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def generate_pseudo_gtbox(boxes, cls_prob, im_labels):
"""Get proposals from fuse_matrix
inputs are all variables"""
pre_nms_topN = 50
nms_Thresh = 0.1
num_images, num_classes = im_labels.size()
boxes = boxes[:,1:]
assert num_images == 1, 'batch size shoud be equal to 1'
im_labels_tmp = im_labels[0, :]
labelList = im_labels_tmp.data.nonzero().view(-1)
gt_boxes = []
gt_classes = []
gt_scores = []
for i in labelList:
scores, order = cls_prob[:,i].contiguous().view(-1).sort(descending=True)
if pre_nms_topN > 0:
order = order[:pre_nms_topN]
scores = scores[:pre_nms_topN].view(-1, 1)
proposals = boxes[order.data, :]
keep = nms(torch.cat((proposals, scores), 1).data, nms_Thresh)
proposals = proposals[keep, :]
scores = scores[keep,]
gt_boxes.append(proposals)
gt_classes.append(torch.ones(keep.size(0),1)*(i+1)) # return idx=class+1 to include the background
gt_scores.append(scores.view(-1,1))
gt_boxes = torch.cat(gt_boxes)
gt_classes = torch.cat(gt_classes)
gt_scores = torch.cat(gt_scores)
proposals = {'gt_boxes' : gt_boxes,
'gt_classes': gt_classes,
'gt_scores': gt_scores}
# print(gt_boxes.size())
# print(gt_classes.size())
# print(type(gt_boxes))
# print(type(gt_classes))
return torch.cat([gt_boxes,gt_classes],1),proposals
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:43,代码来源:generate_pseudo_gtbox.py
示例9: demo
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def demo(net, image_name):
"""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)
im = cv2.imread(im_file)
# Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
scores, boxes = im_detect(net, im)
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_ind, cls in enumerate(CLASSES[1:]):
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(torch.from_numpy(dets), NMS_THRESH)
dets = dets[keep.numpy(), :]
vis_detections(im, cls, dets, thresh=CONF_THRESH)
开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:28,代码来源:demo.py
示例10: apply_nms
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper 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))[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
示例11: test_net
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def test_net(sess, net, imdb, weights_filename, thresh=0.05):
np.random.seed(cfg.RNG_SEED)
"""Test a SSH 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)]
output_dir = get_output_dir(imdb, weights_filename)
# 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()
inds = np.where(scores[:, 0] > thresh)[0]
scores = scores[inds, 0]
boxes = boxes[inds, :]
dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
keep = nms(dets, cfg.TEST.NMS)
dets = dets[keep, :]
all_boxes[i] = det
_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.pkl')
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)
示例12: demo
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def demo(sess, net, image_name):
"""Detect object classes in an image using pre-computed object proposals."""
# Load the demo image
once_time = 0
im = cv2.imread(img_path)
# print('>>>>>>>', im.shape[0], im.shape[1])
# Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
scores, boxes = im_detect(sess, net, im)
timer.toc()
once_time = timer.total_time
print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time, boxes.shape[0]))
# Visualize detections for each class
CONF_THRESH = 0.85
NMS_THRESH = 0.3
inds = np.where(scores[:, 0] > CONF_THRESH)[0]
scores = scores[inds, 0]
boxes = boxes[inds, :]
dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
keep = nms(dets, NMS_THRESH)
dets = dets[keep, :]
print('>>>>>num_faces:', dets.shape[0])
cv2_vis(im, CLASSES[1], dets)
return once_time
示例13: pre_process
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def pre_process(text_proposals, scores):
keep_inds = np.where(scores > TextLineCfg.TEXT_PROPOSALS_MIN_SCORE)[0]
text_proposals, scores = text_proposals[keep_inds], scores[keep_inds]
# 按得分排序
sorted_indices = np.argsort(scores.ravel())[::-1]
text_proposals, scores = text_proposals[sorted_indices], scores[sorted_indices]
# 对proposal做nms
keep_inds = nms(np.hstack((text_proposals, scores)), TextLineCfg.TEXT_PROPOSALS_NMS_THRESH)
text_proposals, scores = text_proposals[keep_inds], scores[keep_inds]
return text_proposals, scores
示例14: proposal_layer
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper import nms [as 别名]
def proposal_layer(rpn_cls_prob, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchors, num_anchors):
"""A simplified version compared to fast/er RCNN
For details please see the technical report
"""
if type(cfg_key) == bytes:
cfg_key = cfg_key.decode('utf-8')
pre_nms_topN = cfg[cfg_key].RPN_PRE_NMS_TOP_N
post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
nms_thresh = cfg[cfg_key].RPN_NMS_THRESH
im_info = im_info[0]
# Get the scores and bounding boxes
scores = rpn_cls_prob[:, :, :, num_anchors:]
rpn_bbox_pred = rpn_bbox_pred.reshape((-1, 4))
scores = scores.reshape((-1, 1))
proposals = bbox_transform_inv(anchors, rpn_bbox_pred)
proposals = clip_boxes(proposals, im_info[:2])
# Pick the top region proposals
order = scores.ravel().argsort()[::-1]
if pre_nms_topN > 0:
order = order[:pre_nms_topN]
proposals = proposals[order, :]
scores = scores[order]
# Non-maximal suppression
keep = nms(np.hstack((proposals, scores)), nms_thresh)
# Pick th top region proposals after NMS
if post_nms_topN > 0:
keep = keep[:post_nms_topN]
proposals = proposals[keep, :]
scores = scores[keep]
# Only support single image as input
batch_inds = np.zeros((proposals.shape[0], 1), dtype=np.float32)
blob = np.hstack((batch_inds, proposals.astype(np.float32, copy=False)))
return blob, scores
示例15: apply_nms
# 需要导入模块: from model import nms_wrapper [as 别名]
# 或者: from model.nms_wrapper 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))[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