= detector(img, 1) # len(dets) 即为检测到的人脸个数 print("Number of faces detected: {}".format(len(dets dets, scores, idx = detector.run(img, 1, -1) for i, d in enumerate(dets): print("Detection batch_size = 128) # len(dets) 即为检测到的人脸个数 print("Number of faces detected: {}".format(len(dets = detector(img, 1) # len(dets) 是检测到的人脸数量 print("Number of faces detected: {}".format(len(dets (len(dets))) for i, d in enumerate(dets): print("Detection {}: Left: {} Top: {} Right: {}
/demo_frame, dets[j][i].prob, 1, avg[i].prob, 1); avg[i].objectness += dets[j][i].objectness * /demo_frame; avg[i].bbox.x += dets[j][i].bbox.x * 1. = dets[0][i].objectness; } */ //非极大值抑制, if (nms > 0) do_nms_obj(dets, nboxes, l.classes [0]和dets[0].prob[0]这两个指针都是空的,把空指针传入printf就只能等着程序崩溃了。 */ if(nboxes>0) { printf("%f\n",dets[0].prob[0]*100); if(dets[0].prob[0]*100>
= np.hstack((cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32) keep = nms(dets, NMS_THRESH) dets = dets[keep, :] #draw #vis_detections(im, cls, dets, thresh=CONF_THRESH) font = cv2 [:, -1] >= CONF_THRESH)[0] if len(inds) > 0: for i in inds: bbox = dets[i, :4 ] score = dets[i, -1] cv2.rectangle(im,(bbox[0], bbox[1]), (bbox[2], bbox[3]) , NMS_THRESH) dets = dets[keep, :] im=vis_detections_video(im, cls, dets, thresh=CONF_THRESH
, all_dets, thresh, scoring_method='ID', beta=1.0): """ 对 all_dets 进行边界框投票(bounding-box voting ) 来改善 top_dets. x2 y2, sore] # all_dets is [N, 5] each row is [x1 y1 x2 y2, sore] top_dets_out = top_dets.copy () top_boxes = top_dets[:, :4] all_boxes = all_dets[:, :4] all_scores = all_dets[:, 4] return [] return cython_nms.nms(dets, thresh) def soft_nms(dets, sigma=0.5, overlap_thresh=0.3,
四、使用python来简单模拟一个NMS过程 # python3 import numpy as np def py_nms(dets, thresh): """Pure Python NMS #x1、y1、x2、y2、以及score赋值 x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3 ] scores = dets[:, 4] #每一个候选框的面积 areas = (x2 - x1 + 1) * (y2 - y1 + 1) #order是按照score 1,所以要把这个1加回来 order = order[inds + 1] return keep # test if __name__ == "__main__": dets = py_nms(dets, thresh) print(keep_dets) print(dets[keep_dets]) 五、NMS loss 值的注意的是对多类别检测任务
# 人脸检测 dets = self.detector(img, 1) x, y, w, h = dets[0].left(), dets[0].top(), dets[ 0].right() - dets[0].left(), dets[0].bottom() - dets[0].top() # 关键点检测 shape = self.predictor (img, dets[0]) point1 = shape.parts()[0] point2 = shape.parts(2) # 求两点中心 point2.x) // 2, (point1.y + point2.y) // 2) 接下来是按照比例缩小帽子的图片 # 帽子和人脸转换比例 hat_w = int(round(dets [0].right()/1.5)) hat_h = int(round(dets[0].bottom() / 2)) if hat_h > y:
: ('ZF', 'ZF_faster_rcnn_final.caffemodel')} def vis_detections(im, class_name, dets inds = np.where(dets[:, -1] >= thresh)[0] if len(inds) == 0: return im = im[:, :, (2 plt.subplots(figsize=(12, 12)) ax.imshow(im, aspect='equal') for i in inds: bbox = dets [i, :4] score = dets[i, -1] ax.add_patch( plt.Rectangle((bbox[0], bbox[1 , NMS_THRESH) dets = dets[keep, :] vis_detections(im, cls, dets, thresh=CONF_THRESH)
= detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d:Left %d Top ) dlib.hit_enter_to_continue() 代码很简单,通过imread读取照片,然后进行检测,输出结果为dets的list,有几张人脸就会有几个item, 每个item都有.left 最后通过win.add_overlay(dets)可以将标记的框显示在原图上。 原始照片 ? 输出照片 ? 其实我们就可以使用这个功能做一个简单的应用,用来检测图片或者视频中人脸的个数。 = detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d: Left % = detector(img) print('检测到了 %d 个人脸' % len(dets)) # 这里假设每张图只有一个人脸 shape = predictor(img, dets[0])
= detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d:Left %d Top ) dlib.hit_enter_to_continue() 代码很简单,通过imread读取照片,然后进行检测,输出结果为dets的list,有几张人脸就会有几个item, 每个item都有.left 最后通过win.add_overlay(dets)可以将标记的框显示在原图上。 原始照片 ? 输出照片 ? 其实我们就可以使用这个功能做一个简单的应用,用来检测图片或者视频中人脸的个数。 = detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d: Left %d Top = detector(img) print('检测到了 %d 个人脸' % len(dets)) # 这里假设每张图只有一个人脸 shape = predictor(img, dets[0])
, 'ZF_faster_rcnn_final.caffemodel')} #增加ax参数 def vis_detections(im, class_name, dets inds = np.where(dets[:, -1] >= thresh)[0] if len(inds) == 0: return # 删除这三行 # im = im plt.subplots(figsize=(12, 12)) # ax.imshow(im, aspect='equal') for i in inds: bbox = dets [i, :4] score = dets[i, -1] ax.add_patch( plt.Rectangle((bbox[0], bbox[1 , NMS_THRESH) dets = dets[keep, :] #将ax做为参数传入vis_detections vis_detections(im
, unmatched_trks = associate_detections_to_trackers(dets, trks, self.iou_threshold) # 如果匹配上 则更新修正当前检测框 for m in matched: self.trackers[m[1]].update(dets[m[0], :]) # 如果检测框未匹配上,则当作新目标,新起航迹 for i in unmatched_dets: trk = KalmanBoxTracker(dets[i, :] ): frame += 1 # 从1帧开始 dets = seq_dets[seq_dets[:, 0] == frame, 2:7] dets[:, (dets) # kalman 预测与更新 trackers = mot_tracker.trackers image_path = os.path.join(".
= detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d:Left %d Top ) dlib.hit_enter_to_continue() 代码很简单,通过imread读取照片,然后进行检测,输出结果为dets的list,有几张人脸就会有几个item, 每个item都有.left 最后通过win.add_overlay(dets)可以将标记的框显示在原图上。 原始照片 输出照片 其实我们就可以使用这个功能做一个简单的应用,用来检测图片或者视频中人脸的个数。 = detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d: Left % = detector(img) print('检测到了 %d 个人脸' % len(dets)) # 这里假设每张图只有一个人脸 shape = predictor(img, dets[0])
by Ross Girshick # -------------------------------------------------------- import numpy as np # dets : 检测的 boxes 及对应的 scores; # thresh: 设定的阈值 def nms(dets, thresh): # boxes 位置 x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3] # boxes scores scores = dets[:,
format(index[1], dets[k, -1], dets[k, 0] + 1, dets[k, 1] + 1, dets[k, 2] + 1, dets[k, 3] + 1)) def do_python_eval(output_dir='output', use_07=True): cachedir = detections[0, j, :] mask = dets[:, 0].gt(0.).expand(5, dets.size(0)).t() dets = torch.masked_select(dets, mask).view(-1, 5) if dets.size(0) == 0: continue cls_dets = np.hstack((boxes.cpu().numpy(), scores[:, np.newaxis])).
========Error description: {could_not_start,rabbit, {{badmatch, {error, {{{badmatch, {error, {not_a_dets_file , "/var/lib/rabbitmq/mnesia/rabbit@n1/recovery.dets"}}}, [{rabbit_recovery_terms,open_table,0, [{file ,"/var/lib/rabbitmq/mnesia/rabbit@n1/recovery.dets"}}},[{rabbit_recovery_terms,open_table,0,[{file,"src terminating in do_boot ()Crash dump is being written to: erl_crash.dump...done 解决办法: find / -name recovery.dets 然后使用 rm 命令删除掉 recoer.dets 文件 问题3: 使用命令 rabbitmq-server start 报错如下: 提示 no space left on device /usr
NMS的实现(Pytorch代码) from __future__ import absolute_import import numpy as np import torch def nms(dets , thresh): dets = dets.numpy() x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3] scores = dets[:, 4] areas = (x2 - x1 + 1) * (y2 - y1 + 1) order = scores.argsort
import cv2 import numpy as np def py_nms(dets, thresh): """Pure Python NMS baseline. """ # x1、y1、x2、y2、以及score赋值 # (x1、y1)(x2、y2)为box的左上和右下角标 x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3] scores = dets[:, 4] # 每一个候选框的面积 areas = print(data_hstack) # 极大值抑制 返回对应的索引值 keep = py_nms(data_hstack,0.3) print(keep,len(keep)) # 取出索引对应的矩形框 dets = data_hstack[keep] print(dets,len(dets)) count = 0 for det in dets: count += 1 cv2.rectangle
dlib.image_window() paths = glob.glob('faces/*.jpg') print(paths) for path in paths: img = imread(path) dets = detector(img) print('检测到了 %d 个人脸' % len(dets)) for i, d in enumerate(dets): print('- %d:Left % d.left(), d.top(), d.right(), d.bottom())) win.clear_overlay() win.set_image(img) win.add_overlay(dets
(46).png") if img is None: print("the image file does not exist") # 与人脸检测程序相同,使用detector进行人脸检测 dets 为返回的结果 dets = detector(img, 1) # 使用enumerate 函数遍历序列中的元素以及它们的下标 # 下标k即为人脸序号 # left:人脸左边距离图片左边界的距离 ;right :人脸右边距离图片左边界的距离 # top:人脸上边距离图片上边界的距离 ;bottom:人脸下边距离图片上边界的距离 for k, d in enumerate(dets): print("dets ') font = cv2.FONT_HERSHEY_SIMPLEX def faceDetect(img): global fdetector, predictor, font dets ): # print(f"dets{d}") # print(f"Detection {k}: Left: {d.left()} Top: {d.top()} Right
检测过程完成后,数组dets包含表单(r,c,s,q),其中r,c,s指定人脸区域的位置(行,列)和大小,q表示检测分数。该地区得分越高,越有可能是人脸。 ctx.arc(dets[i][1], dets[i][0], dets[i][2]/2, 0, 2*Math.PI, false); ctx.lineWidth = 3; pico.js中的实现方式是: dets = pico.cluster_detections(dets, 0.2); // set IoU threshold to 0.2 IoU阈值设置为0.2。 现在我们不再从单帧中检测聚类,而是在聚类之前进行累加: dets = pico.run_cascade(image, facefinder_classify_region, params); dets = update_memory(dets); // accumulates detections from last f frames dets = pico.cluster_detections(dets