コード例 #1
0
    max_im_shrink = (
        0x7fffffff / 577.0 /
        (img.shape[0] * img.shape[1]))**0.5  # the max size of input image
    shrink = max_im_shrink if max_im_shrink < 1 else 1
    # print('max_im_shrink:', max_im_shrink)
    det0 = detect_face(img)
    det1 = detect_face(img, flip=True)
    # det = np.row_stack((det0, det1))
    det2 = im_det_ms_pyramid(img, max_im_shrink)
    # merge all test results via bounding box voting
    det = np.row_stack((det0, det1, det2))
    keep_index = np.where(
        np.minimum(det[:, 2] - det[:, 0], det[:, 3] -
                   det[:, 1]) >= 2)[0]  # >= 3
    dets = det[keep_index, :]
    dets = bbox_process.soft_bbox_vote(dets, thre=soft_box_thre, score=score)
    # keep = nms(dets, 0.4, usegpu=True, gpu_id=0)
    # dets = det[keep, :]

    keep_index = np.where((dets[:, 2] - dets[:, 0] + 1) *
                          (dets[:, 3] - dets[:, 1] + 1) >= 2**2)[0]
    dets = dets[keep_index, :]

    with open(txtpath, 'w') as file:
        file.write('{:s}\n'.format(filename))
        file.write('{:d}\n'.format(len(dets)))
        for line in dets:
            file.write('{:.0f} {:.0f} {:.0f} {:.0f} {:.3f}\n'.format(
                line[0], line[1], line[2] - line[0] + 1, line[3] - line[1] + 1,
                line[4]))
コード例 #2
0
					elif st[i] == 2.0:
						index = np.where(
							np.minimum(det_temp[:, 2] - det_temp[:, 0] + 1, det_temp[:, 3] - det_temp[:, 1] + 1) < 48)[0]
						det_temp = det_temp[index, :]
					elif st[i] == 2.25:
						index = np.where(
							np.minimum(det_temp[:, 2] - det_temp[:, 0] + 1, det_temp[:, 3] - det_temp[:, 1] + 1) < 32)[0]
						det_temp = det_temp[index, :]
					det_s = np.row_stack((det_s, det_temp))
			return det_s

		max_im_shrink = (0x7fffffff / 577.0 / (img.shape[0] * img.shape[1])) ** 0.5  # the max size of input image
		shrink = max_im_shrink if max_im_shrink < 1 else 1
		det0 = detect_face(img)
		det1 = detect_face(img, flip=True)
		det2 = im_det_ms_pyramid(img, max_im_shrink)
		# merge all test results via bounding box voting
		det = np.row_stack((det0, det1, det2))
		keep_index = np.where(np.minimum(det[:, 2] - det[:, 0], det[:, 3] - det[:, 1]) >= 3)[0]
		det = det[keep_index, :]
		dets = bbox_process.soft_bbox_vote(det, thre=0.4)
		keep_index = np.where((dets[:, 2] - dets[:, 0] + 1) * (dets[:, 3] - dets[:, 1] + 1) >= 6 ** 2)[0]
		dets = dets[keep_index, :]

		with open(txtpath, 'w') as f:
			f.write('{:s}\n'.format(filename))
			f.write('{:d}\n'.format(len(dets)))
			for line in dets:
				f.write('{:.0f} {:.0f} {:.0f} {:.0f} {:.3f}\n'.
						format(line[0], line[1], line[2] - line[0] + 1, line[3] - line[1] + 1, line[4]))
	print time.time() - start_time
コード例 #3
0
def detect_main(model, val_data, C):
    C.size_test = [0, 0]
    num_imgs = len(val_data)
    print 'num of val samples: {}'.format(num_imgs)
    meta = {}
    meta['filepath'] = []
    meta['true_box'] = []
    meta['pred_box'] = []
    progbar = generic_utils.Progbar(num_imgs)
    start_time = time.time()
    for f in range(num_imgs):
        filepath = val_data[f]['filepath']
        # filename = filepath.split('/')[-1].split('.')[0]
        img = cv2.imread(filepath)
        max_im_shrink = (
            0x7fffffff / 577.0 /
            (img.shape[0] * img.shape[1]))**0.5  # the max size of input image
        det0 = detect_face(model, img, C)
        det1 = detect_face(model, img, C, flip=True)
        det2 = im_det_ms_pyramid(model, img, C, max_im_shrink)
        det = np.row_stack((det0, det1, det2))
        keep_index = np.where(
            np.minimum(det[:, 2] - det[:, 0], det[:, 3] -
                       det[:, 1]) >= 2)[0]  # >= 3
        dets = det[keep_index, :]
        dets = bbox_process.soft_bbox_vote(dets,
                                           thre=soft_box_thre,
                                           score=score)

        keep_index = np.where((dets[:, 2] - dets[:, 0] + 1) *
                              (dets[:, 3] - dets[:, 1] + 1) >= 2**2)[0]
        dets = dets[keep_index, :]

        gt_bboxes = val_data[f]['bboxes']

        meta['filepath'].append(filepath)
        meta['true_box'].append(dets)
        meta['pred_box'].append(gt_bboxes)

        if f % 10 == 0:
            progbar.update(f)

    best_mae = 1e8
    best_mse = 1e8
    best_thr = 0.4
    mae_dict = {}
    mse_dict = {}
    for i in range(30, 51):
        thr_i = i * 0.01
        pred_counts = []
        true_counts = []
        for true_box, pred_box in zip(meta['true_box'], meta['pred_box']):
            true_box = true_box[true_box[:, 4] > thr_i]
            pred_count = true_box.shape[0]
            true_count = pred_box.shape[0]
            pred_counts.append(pred_count)
            true_counts.append(true_count)

        pred_counts = np.array(pred_counts, dtype='float')
        true_counts = np.array(true_counts, dtype='float')

        mae = np.mean(np.abs(true_counts - pred_counts))
        mse = np.sqrt(np.mean((true_counts - pred_counts)**2))

        mae_dict['{:0.2f}'.format(thr_i)] = float(mae)
        mse_dict['{:0.2f}'.format(thr_i)] = float(mse)

        if mae <= best_mae:
            best_mae = float(mae)
            best_mse = float(mse)
            best_thr = float(thr_i)

    print time.time() - start_time

    return best_mae, best_mse, best_thr, mae_dict, mse_dict