gpt4 book ai didi

machine-learning - 使用 P. Viola、M. Jones 框架计算最佳阈值的最佳方法

转载 作者:行者123 更新时间:2023-11-30 08:23:27 26 4
gpt4 key购买 nike

我正在尝试用 C++ 实现 P. Viola 和 M. Jones 检测框架(一开始只是简单的序列分类器 - 不是级联版本)。我认为我已经设计了所有必需的类和模块(例如积分图像、Haar 特征),尽管最重要的是:AdaBoost 核心算法。

我读过 P. Viola 和 M. Jones 的原始论文以及许多其他出版物。不幸的是我仍然不明白我应该如何找到一个弱分类器的最佳阈值?我只发现了对“加权中位数”和“高斯分布”算法以及许多数学公式的少量引用......

我尝试过使用OpenCV Train Cascade模块源作为模板,但它太全面了,对代码进行逆向工程非常耗时。我还编写了自己的简单代码来理解自适应增强的思想。

问题是:您能否向我解释一下计算一个弱分类器的最佳阈值的最佳方法?

下面我将展示 AdaBoost 伪代码,该代码是根据 Google 中找到的示例重写的,但我不确定它是否是正确的方法。一个弱分类器的计算非常慢(几个小时),我尤其对计算最佳阈值的方法有疑问。

(1) AdaBoost::FindNewWeakClassifier
(2) AdaBoost::CalculateFeatures
(3) AdaBoost::FindBestThreshold
(4) AdaBoost::FindFeatureError
(5) AdaBoost::NormalizeWeights
(6) AdaBoost::FindLowestError
(7) AdaBoost::ClassifyExamples
(8) AdaBoost::UpdateWeights

DESCRIPTION (1)
-Generates all possible arrangement of features in detection window and put to the vector
DO IN LOOP
-Runs main calculating function (2)
END

DESCRIPTION(2)
-Normalizes weights (5)
DO FOR EACH HAAR FEATURE
-Puts sequentially next feature from list on all integral images
-Finds the best threshold for each feature (3)
-Finds the error for each the best feature in current iteration (4)
-Saves errors for each the best feature in current iteration in array
-Saves threshold for each the best feature in current iteration in array
-Saves the threshold sign for each the best feature in current iteration in array
END LOOP
-Finds for classifier index with the lowest error selected by above loop (6)
-Gets the value of error from the best feature
-Calculates the value of the best feature in the all integral images (7)
-Updates weights (8)
-Adds new, weak classifier to vector

DESCRIPTION (3)
-Calculates an error for each feature threshold on positives integral images - seperate for "+" and "-" sign (4)
-Returns threshold and sign of the feature with the lowest error

DESCRIPTION(4)
- Returns feature error for all samples, by calculating inequality f(x) * sign < sign * threshold

DESCRIPTION (5)
-Ensures that samples weights are probability distribution

DESCRIPTION (6)
-Finds the classifier with the lowest error

DESCRIPTION (7)
-Calculates a value of the best features at all integral images
-Counts false positives number and false negatives number

DESCRIPTION (8)
-Corrects weights, depending on classification results

感谢您的帮助

最佳答案

在原始的 viola-Jones 论文中 here ,第 3.1 节学习讨论(准确地说,第 4 段)您将了解找到最佳阈值的过程。

我将在下面快速总结该方法。

<小时/>

每个特征的最佳阈值取决于样本权重,因此在 adaboost 的每次迭代中计算。如伪代码中所述,保存最佳弱分类器的阈值。

在每一轮中,对于每个弱分类器,你都必须根据特征值来排列N个训练样本。设置阈值会将这个序列分成两部分。两个部分都将包含大多数正样本或负样本以及少量其他类型的样本。

  • T+:正样本权重总和
  • T-:负样本权重总和
  • S+:低于阈值的正样本权重之和
  • S-:低于阈值的负样本权重之和

此特定阈值的错误是 -

e = MIN((S+) + (T-) - (S-), (S-) + (T+) - (S+))

为什么是最小值?这是一个例子:
如果样本和阈值是这样的 -

+ + + + + - - | + + - - - - -

在第一轮中,如果所有权重都相等(=w),则取最小值会产生 4*w 的误差,而不是 10*w

您可以计算所有 N 种可能的样本分离方式的误差。
最小误差将为您提供阈值的范围。实际阈值可能是相邻特征值的平均值(但我不确定,对此进行一些研究)。
这是 DO FOR EACH HAAR FEATURE 循环中的第二步。
与 OpenCV 一起给出的级联是由 Rainer Lienhart 创建的,我不知道他使用了什么方法。您可以密切关注 OpenCV 源代码,以获得对此过程的任何进一步改进。

关于machine-learning - 使用 P. Viola、M. Jones 框架计算最佳阈值的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9777282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com