11 KiB
Executable File
layout | title | subtitle | description | excerpt | date | author | tags | categories | published | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
post | Deep Learning Haar Cascade Explained | 翻译 | 这是我认为最通俗易懂的 Haar 级联分类器的解释说明,文末视频非常形象。 | 2020-03-04 14:42:00 | Rick Chan |
|
|
true |
[原文连接]http://www.willberger.org/cascade-haar-explained/
“Alright! This is where we start having some fun! The concept behind the Haar Cascade and how it is used in the real world is nothing short of amazing. So what is it?”
Haar 级联分类器的背后思想以及其现实应用实在令人倍感惊奇。
Haar cascade
“Haar Cascade is a machine learning object detection algorithm used to identify objects in an image or video and based on the concept of features proposed by Paul Viola and Michael Jones in their paper "Rapid Object Detection using a Boosted Cascade of Simple Features" in 2001.“
Haar 级联分类器是一种机器学习算法,最初由 Paul Viola 和 Michael Jones 在 2001 年的论文《Rapid Object Detection using a Boosted Cascade of Simple Features》中提出。该算法能够通过特征来识别图像或视频中的物体。
“It is a machine learning based approach where a cascade function is trained from a lot of positive and negative images. It is then used to detect objects in other images.”
通过 positive images(包含检测目标的样本) 和 negative images(不包含检测目标的样本)样本集进行训练的级联分类器,能够检测其他图像中的目标物体。
“The algorithm has four stages:
- Haar[1] Feature Selection
- Creating Integral Images[2]
- Adaboost[3] Training
- Cascading Classifiers“
Haar 级联分类器主要有四个步骤:
- Haar[1] 特征选择
- 创建积分图[2]
- Adaboost[3] 训练
- 级联各个分类器
“It is well known for being able to detect faces and body parts in an image, but can be trained to identify almost any object.”
Haar 级联分类器最著名的应用是检测图像中的人脸或身体,但其实也可以检测其他物体。
“Lets take face detection as an example. Initially, the algorithm needs a lot of positive images of faces and negative images without faces to train the classifier. Then we need to extract features from it.”
本文以人脸检测为例。首先需要大量包含人脸的 positive image 和不包含人脸的 negative image 来训练分类器。然后我们从其中提取特征。
“First step is to collect the Haar Features. A Haar feature considers adjacent rectangular regions at a specific location in a detection window, sums up the pixel intensities in each region and calculates the difference between these sums.”
第一步是收集 Haar 特征。可以将 Haar 特征看作检测窗口中相邻的举行区域,将各自区域的像素强度加合,然后计算它们的差值。
“Integral Images are used to make this super fast.”
可以使用积分图加快这一运算过程。
“But among all these features we calculated, most of them are irrelevant. For example, consider the image below. Top row shows two good features. The first feature selected seems to focus on the property that the region of the eyes is often darker than the region of the nose and cheeks. The second feature selected relies on the property that the eyes are darker than the bridge of the nose. But the same windows applying on cheeks or any other place is irrelevant.”
但是,这些特征中的很大一部分是与任务目标不相关的(没有意义的特征)。以下图为例,应用第一行的选择窗口可以得到两个好的特征:选取第一个特征,主要是由于眼部区域通常比鼻子和脸颊更黑;选取第二个特征则依赖于眼部比鼻梁更黑这一现象。但是,将同样的检测窗口应用于脸颊或其他部位则得不到有意义的特征。
“So how do we select the best features out of 160000+ features? This is accomplished using a concept called Adaboost which both selects the best features and trains the classifiers that use them. This algorithm constructs a “strong” classifier as a linear combination of weighted simple “weak” classifiers. The process is as follows.”
在人脸检测这样的任务中,特征总数足有 160000 多个,如何从中选取最有意义的特征?这由 Adaboost 算法完成,该算法会选取最佳特征并训练分类器来使用这些特征。Adaboost 算法引入了强分类器和弱分类器的概念,强分类器由弱分类器线性组合而成。其算法过程如下:
“During the detection phase, a window of the target size is moved over the input image, and for each subsection of the image and Haar features are calculated. You can see this in action in the video below. This difference is then compared to a learned threshold that separates non-objects from objects. Because each Haar feature is only a "weak classifier" (its detection quality is slightly better than random guessing) a large number of Haar features are necessary to describe an object with sufficient accuracy and are therefore organized into cascade classifiers to form a strong classifier.”
在检测阶段,一个特定的窗口在输入图像上移动,并在每个位置上计算 Haar 特征。下面的视频演示了这一过程。计算结果将与阈值进行比较以区分是否为检测目标,这个阈值是通过学习得到的。由于每个 Haar 特征只是一个“弱分类器”(弱分类器的检测质量仅比随即猜测好一点儿),我们需要大量的 Haar 特征才能够对目标进行精确的检测,因此这些弱分类器被级联成了强分类器。
Cascade Classifier
“The cascade classifier[a] consists of a collection of stages, where each stage is an ensemble of weak learners. The weak learners are simple classifiers called decision stumps. Each stage is trained using a technique called boosting. Boosting provides the ability to train a highly accurate classifier by taking a weighted average of the decisions made by the weak learners.”
级联分类器[a]由一系列小的阶段组成,每个阶段就是一个弱学习过程。弱学习过程是一个被称作单层分类器的简单分类器。每个阶段由 boosting 算法进行训练。通过对每个阶段的决策进行加权,Boosting 提供了训练高准确度分类器的方法。
“Each stage of the classifier labels the region defined by the current location of the sliding window as either positive or negative. Positive indicates that an object was found and negative indicates no objects were found. If the label is negative, the classification of this region is complete, and the detector slides the window to the next location. If the label is positive, the classifier passes the region to the next stage. The detector reports an object found at the current window location when the final stage classifies the region as positive.”
每个阶段的分类器对滑动窗口的当前区域打标签(positive 或 negative)。Positive 意味着检测到了目标,negative 意味着没有检测到目标。如果没有检测到目标则完成当前区域的检测,滑动窗口移动到下一个区域。如果检测结果为 positive,则分类器将当前区域传递给下一个阶段继续进行检测。当所有检测阶段都返回 positive,那么检测器报告在当前位置发现了目标物。
“The stages are designed to reject negative samples as fast as possible. The assumption is that the vast majority of windows do not contain the object of interest. Conversely, true positives are rare and worth taking the time to verify.”
原文标注
[1] Haar
“A Haar-like feature considers adjacent rectangular regions at a specific location in a detection window, sums up the pixel intensities in each region and calculates the difference between these sums.“
“This difference is then used to categorize subsections of an image. For example, let us say we have an image database with human faces. It is a common observation that among all faces the region of the eyes is darker than the region of the cheeks. Therefore a common Haar feature for face detection is a set of two adjacent rectangles that lie above the eye and the cheek region. The position of these rectangles is defined relative to a detection window that acts like a bounding box to the target object (the face in this case).“
[2] Integral Images
“An integral image is summed-area table is a data structure and algorithm for quickly and efficiently generating the sum of values in a rectangular subset of a grid. To understand this look at image 1 and image 2. Image 1 is the source table, Image 2 is the summation table. Notice in Image 2 row 1, col 2 value 33 is sum of Image 1 row 1 (col 1 + col 2).“
[3] Adaboost
“Problems in machine learning often suffer from the curse of dimensionality — each sample may consist of a huge number of potential features (for instance, there can be 162,336 Haar features, as used by the Viola–Jones object detection framework, in a 24×24 pixel image window), and evaluating every feature can reduce not only the speed of classifier training and execution, but in fact reduce predictive power, per the Hughes Effect.[3] Unlike neural networks and SVMs, the AdaBoost training process selects only those features known to improve the predictive power of the model, reducing dimensionality and potentially improving execution time as irrelevant features need not be computed.“
译注
[4] Cascade Classifier
级联分类器是将一些小的分类过程组合成完整分类器的方法。以下图为例,需要将图中的“+”和“-”数据分开,仅靠一个分类过程很难实现。
但将下图中的三种分类方法组合到一起就可以得到一个非常好的分类器。其中每个分类方法都是级联分类器中的一个弱分类器,它们组合成了一个强分类器。注意,每个弱分类器都只对部分数据进行了分类。
参考资料
以下是译者本人提供的一些额外参考资料:
人脸检测之Haar分类器
What’s the Difference Between Haar-Feature Classifiers and Convolutional Neural Networks?
Computer Vision — Detecting objects using Haar Cascade Classifier
Deep Learning Haar Cascade Explained
浅析人脸检测之Haar分类器方法:Haar特征、积分图、AdaBoost、级联
AdaBoost & AdaRank