与 Hugo 同步.

Signed-off-by: lion.chan <cy187lion@sina.com>
This commit is contained in:
lion.chan 2022-09-06 09:22:19 +08:00
parent cda85248b4
commit 7bdfb13a81
10 changed files with 113 additions and 35 deletions

View File

@ -4,20 +4,29 @@ title: "Deep Learning Haar Cascade Explained"
subtitle: ""
description: "翻译"
excerpt: "这是我认为最通俗易懂的 Haar 级联分类器的解释说明,文末视频非常形象。"
date: 2020-11-24 11:26:00
date: 2022-09-06 09:07:00
author: "Rick Chan"
tags: ["AI", "Classifier", "Haar"]
categories: ["Algorithm"]
published: true
---
- [1. Haar cascade](#1-haar-cascade)
- [2. Cascade Classifier](#2-cascade-classifier)
- [3. Haar Cascade - Facial Detection IN ACTION](#3-haar-cascade---facial-detection-in-action)
- [4. Next Steps](#4-next-steps)
- [5. References](#5-references)
- [6. 原文标注](#6-原文标注)
- [7. 译注](#7-译注)
- [8. 外部参考资料](#8-外部参考资料)
[原文连接](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
## 1. 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.“
@ -49,11 +58,11 @@ Haar 级联分类器最著名的应用是检测图像中的人脸或身体,但
本文以人脸检测为例。首先需要大量包含人脸的阳性 image 和不包含人脸的阴性 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.”
“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 特征看作检测窗口中相邻的举行区域,将各自区域的像素强度加合,然后计算它们的差值。
第一步是收集 Haar 特征。可以将 Haar 特征看作检测窗口中相邻的举行区域,将各自区域的像素强度加合,然后计算它们的差值。
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/001.jpg)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/001.jpg)
“Integral Images are used to make this super fast.”
@ -63,7 +72,7 @@ Haar 级联分类器最著名的应用是检测图像中的人脸或身体,但
但是,这些特征中的很大一部分是与任务目标不相关的(没有意义的特征)。以下图为例,应用第一行的选择窗口可以得到两个好的特征:选取第一个特征,主要是由于眼部区域通常比鼻子和脸颊更黑;选取第二个特征则依赖于眼部比鼻梁更黑这一现象。但是,将同样的检测窗口应用于脸颊或其他部位则得不到有意义的特征。
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/002.png)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/002.png)
“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.”
@ -73,9 +82,9 @@ Haar 级联分类器最著名的应用是检测图像中的人脸或身体,但
在检测阶段,一个特定的窗口在输入图像上移动,并在每个位置上计算 Haar 特征。下面的视频演示了这一过程。计算结果将与阈值进行比较以区分是否为检测目标,这个阈值是通过学习得到的。由于每个 Haar 特征只是一个“弱分类器”(弱分类器的检测质量仅比随即猜测好一点儿),我们需要大量的 Haar 特征才能够对目标进行精确的检测,因此这些弱分类器被级联成了强分类器。
## Cascade Classifier
## 2. Cascade Classifier
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/003.png)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/003.png)
“The cascade classifier[b] 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.”
@ -87,15 +96,15 @@ Haar 级联分类器最著名的应用是检测图像中的人脸或身体,但
“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.
* A true positive occurs when a positive sample is correctly classified.
* A false positive occurs when a negative sample is mistakenly classified as positive.
* A false negative occurs when a positive sample is mistakenly classified as negative.”
- A true positive occurs when a positive sample is correctly classified.
- A false positive occurs when a negative sample is mistakenly classified as positive.
- A false negative occurs when a positive sample is mistakenly classified as negative.”
所有的阶段都被设计为能够快速的滤除阴性采样。这是因为我们假设大部分的滑动窗口不包含待检测目标。相反,真阳性比较稀少,值得多花费一些时间去处理。
* 真阳性:是指被正确分类的阳性采样。
* 假阳性:是指被错误分类的阴性采样。
* 假阴性:是指被错误分类的阳性采样。
- 真阳性:是指被正确分类的阳性采样。
- 假阳性:是指被错误分类的阴性采样。
- 假阴性:是指被错误分类的阳性采样。
“To work well, each stage in the cascade must have a low false negative rate. If a stage incorrectly labels an object as negative, the classification stops, and you cannot correct the mistake. However, each stage can have a high false positive rate. Even if the detector incorrectly labels a nonobject as positive, you can correct the mistake in subsequent stages. Adding more stages reduces the overall false positive rate, but it also reduces the overall true positive rate.”
@ -105,31 +114,31 @@ Haar 级联分类器最著名的应用是检测图像中的人脸或身体,但
训练级联分类器需要一组阳性采样和一组阴性采样图像。可以提供一组包含感兴趣区的阳性图像作为阳性采样。使用 Image Labeler 标记由包围盒框选的目标。Image Labeler 输出阳性采样标签。同时,还需要一组阴性图像,算法函数将自动生成阴性采样。为了达到可接受的精度,需要设置级联深度,特征类型和其他参数。
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/004.png)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/004.png)
“The video below shows this in action.“
下面的视频展示了以上所述的检测过程。
## Haar Cascade - Facial Detection IN ACTION
## 3. Haar Cascade - Facial Detection IN ACTION
“If a picture is worth a thousand words this would be a million words. This is where it all comes together. The Ahh-hah moment.”
“This simple video helped crystalize for me how this algorithm works. Here are some observations:
* Notice how the algorithm moves the window systematically over the image, applying the Haar features as it is trying to detect the face. This is depicted by the green rectangles.
* Notice underneath the red boundary square, we see the classifier executing stages quickly discarding window frames that are clearly not a match (stages 1-25)
* To the right of the stage we see the how well it performed in identifying the face.
* Notice as it gets closer and closer to identifying the face, the number of stages increases into the 20s. (around the 1 minute mark). This demonstrates the cascading effect where the early stages are discarding the input as it has identified them as irrelevant. As it gets closer to finding a face it pays closer attention.”
- Notice how the algorithm moves the window systematically over the image, applying the Haar features as it is trying to detect the face. This is depicted by the green rectangles.
- Notice underneath the red boundary square, we see the classifier executing stages quickly discarding window frames that are clearly not a match (stages 1-25)
- To the right of the stage we see the how well it performed in identifying the face.
- Notice as it gets closer and closer to identifying the face, the number of stages increases into the 20s. (around the 1 minute mark). This demonstrates the cascading effect where the early stages are discarding the input as it has identified them as irrelevant. As it gets closer to finding a face it pays closer attention.”
本文视频能够帮助大家理解算法的工作过程。我们可以观察到下面一些情况。
* 注意观察算法是如何有组织滑动窗口来覆盖图像,应用 Haar 特征并试图检测出人脸。这一过程由绿色矩形来描述。
* 注意,在红色矩形边界下,我们观察到,分类器迅速的丢掉了没匹配成功的窗口。
* 在其余的阶段中,我们能观察到分类器很好的检测出了人脸。
* 注意,随着越来越接近人脸检测结果,检测过程所消耗的时间也越来越长,这表示越接近目标分类器的工作越精细,在检测的初始阶段,分类器只要进行粗略的分类即可。
- 注意观察算法是如何有组织滑动窗口来覆盖图像,应用 Haar 特征并试图检测出人脸。这一过程由绿色矩形来描述。
- 注意,在红色矩形边界下,我们观察到,分类器迅速的丢掉了没匹配成功的窗口。
- 在其余的阶段中,我们能观察到分类器很好的检测出了人脸。
- 注意,随着越来越接近人脸检测结果,检测过程所消耗的时间也越来越长,这表示越接近目标分类器的工作越精细,在检测的初始阶段,分类器只要进行粗略的分类即可。
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/005.gif)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/005.gif)
[点击查看原始视频](https://www.youtube.com/watch?v=hPCTwxF0qf4&feature=youtu.be)
@ -139,13 +148,13 @@ I want to make sure I got this post right. It will be critical that you understa
如果对本文有任何疑问请告知,我需要确保本文的正确性。理解本文的内容是至关重要的,这有助于进入下一个阶段的学习——定制 Haar 级联分类器。
## Next Steps
## 4. Next Steps
“I don't know about you, but I find the best way to understand something is by doing it. Conceptually we now have an idea for how the machine learning Haar Cascade object detection works. Now lets build a real world custom Object Detector, train it, and see it in action. I have a really cool example for us! Click on the button below.”
按钮的连接错了,所以我实在不知道作者所说的 cool example 是哪一个,不过作者网站确实有一些很酷的例子,感兴趣的朋友可以点击连接进入[作者网站](http://www.willberger.org/category/ai/),也可以自行练习一些例子,毕竟理解事物的最好方法就是实践。
## References
## 5. References
1. Wikipedia, Wikipedia. “AdaBoost.” Wikipedia, Wikimedia Foundation, 13 Jan. 2018, en.wikipedia.org/wiki/AdaBoost.
2. Docs, OpenCV. “Face Detection Using Haar Cascades.” OpenCV: Face Detection Using Haar Cascades, 4 Aug. 2017, docs.opencv.org/3.3.0/d7/d8b/tutorial_py_face_detection.html.
@ -153,7 +162,7 @@ I want to make sure I got this post right. It will be critical that you understa
4. Wikipedia, Wikipedia. “Cascading Classifiers.” Wikipedia, Wikimedia Foundation, 15 October. 2013, en.wikipedia.org/wiki/Cascading_classifiers.
5. Mathworks, Mathworks. “Train a Cascade Object Detector” Mathworks, 2017, www.mathworks.com/help/vision/ug/train-a-cascade-object-detector.html.
## 原文标注
## 6. 原文标注
[1] Haar
@ -165,13 +174,13 @@ This difference is then used to categorize subsections of an image. For example,
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).
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/006.png)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/006.png)
[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 ViolaJones 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. 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.
## 译注
## 7. 译注
[a] positive and negative
@ -181,13 +190,13 @@ Problems in machine learning often suffer from the curse of dimensionality — e
级联分类器是将一些小的分类过程组合成完整分类器的方法。以下图为例,需要将图中的“+”和“-”数据分开,仅靠一个分类过程很难实现。
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/007.png)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/007.png)
但将下图中的三种分类方法组合到一起就可以得到一个非常好的分类器。其中每个分类方法都是级联分类器中的一个弱分类器,它们组合成了一个强分类器。注意,每个弱分类器都只对部分数据进行了分类。
![Integral Images](./img/Deep_Learning_Haar_Cascade_Explained/008.png)
![Integral Images](/img/post/Algorithm/Deep_Learning_Haar_Cascade_Explained/008.png)
## 外部参考资料
## 8. 外部参考资料
以下是译者本人提供的一些额外参考资料:

View File

@ -4,13 +4,38 @@ title: "Octave 基本操作"
subtitle: ""
description: "对 Octave 的常用计算功能进行说明。"
excerpt: "描述 Octave 的功能,并对其使用做出基本指导。"
date: 2022-07-28 12:00:00
date: 2022-09-06 09:03:00
author: "Rick Chan"
tags: ["Applications", "Octave"]
categories: ["Software"]
published: true
---
- [1. 基本计算](#1-基本计算)
- [2. 逻辑运算](#2-逻辑运算)
- [3. 变量](#3-变量)
- [4. 向量和矩阵](#4-向量和矩阵)
- [4.1. 向量 / 矩阵的生成](#41-向量--矩阵的生成)
- [4.2. 向量 / 矩阵的属性](#42-向量--矩阵的属性)
- [4.3. 向量 / 矩阵的运算](#43-向量--矩阵的运算)
- [5. 控制语句和函数](#5-控制语句和函数)
- [5.1. for、while、if 语句](#51-forwhileif-语句)
- [5.2. 函数](#52-函数)
- [6. 加载和保存数据](#6-加载和保存数据)
- [7. 绘制图形](#7-绘制图形)
- [8. 矢量](#8-矢量)
- [9. 工具包](#9-工具包)
- [9.1. 安装工具包包](#91-安装工具包包)
- [9.2. 升级工具包](#92-升级工具包)
- [9.3. 查看已安装的工具包](#93-查看已安装的工具包)
- [9.4. 卸载工具包](#94-卸载工具包)
- [9.5. 加载工具包](#95-加载工具包)
- [10. 解符号方程](#10-解符号方程)
- [11. 符号计算带入常数](#11-符号计算带入常数)
- [12. 多项式拟合](#12-多项式拟合)
- [13. 插值](#13-插值)
- [14. 外部参考资料](#14-外部参考资料)
Matlab 是一款大名鼎鼎的数学软件工具,无论是工程计算还是机器学习都可见其身影,其应用十分广泛。其体量非常的庞大,若只是轻量级的应用,可以选用 Matlab 的开源实现——Octave 软件工具。Octave 是一个软件套件,包含一组应用程序和一组算法库,其实现了常用的 Matlab 功能,并且语法完全兼容。并且这是一款开源免费软件,支持 Window/Linux/Mac 等系统。
## 1. 基本计算
@ -896,7 +921,51 @@ p = A * X
其实Octave 能做的远远不止这些,本篇介绍的这些也不过是冰山一角,但对于我们实践机器学习的算法已经基本足够。不要忘记的是,当你对某个函数不清楚的时候,试试 help {func name}。
## 9. 加载软件包
## 9. 工具包
### 9.1. 安装工具包包
工具包检索和下载地址:<https://octave.sourceforge.io/packages.php>
可通过以下命令离线或在线安装工具包。
```m
>> pkg install <path>\<to>\<package name>.tar.gz
>> % 比如
>> pkg install E:\signal-1.4.2.tar.gz
>> pkg install -forge <package name>
>> pkg install 'http://somewebsite.org/image-1.0.0.tar.gz'
```
### 9.2. 升级工具包
```m
>> pkg update
```
### 9.3. 查看已安装的工具包
```m
>> pkg list
Package Name | Version | Installation directory
--------------+---------+-----------------------
image *| 1.0.0 | /home/jwe/octave/image-1.0.0
>>
>> pkg list <package name>
>> % 比如
>> pkg list linear-algebra
Package Name | Version | Installation directory
----------------+---------+-----------------------
linear-algebra | 2.2.3 | D:\Program Files\GNU Octave\Octave-7.2.0\mingw64\share\octave\packages\linear-algebra-2.2.3
```
### 9.4. 卸载工具包
```m
>> pkg uninstall <package name>
```
### 9.5. 加载工具包
```m
>> pkg load <package name>

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

Before

Width:  |  Height:  |  Size: 11 MiB

After

Width:  |  Height:  |  Size: 11 MiB

View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB