百度人脸识别 人脸识别模型_当我说人脸识别很容易时,他们笑了。 但是可以。...

百度人脸识别 人脸识别模型

by Tirmidzi Faizal Aflahi

通过提尔米兹·法扎尔·阿弗拉希

当我说人脸识别很容易时,他们笑了。 但是可以。 (They laughed when I said Face Recognition was easy. But it can be.)

Maybe you have seen it before. Maybe some of you use a face unlock feature that some phones have. This technology called Face Recognition is simply amazing. But, do you think it is hard to make an application based on that technology? It is actually not that hard. You can even make it with less than 10 lines of codes! Seriously. Here is my Face Recognition Tensorflow tutorial, special for you.

也许您以前看过。 也许有些人使用某些手机具有的面部解锁功能。 这项称为人脸识别的技术简直是惊人的。 但是,您认为基于该技术创建应用程序很困难吗? 实际上并不难。 您甚至可以用少于10行的代码来制作它! 说真的 这是我的人脸识别Tensorflow教程,非常适合您。

TL; DR (TL;DR)

Here is the code, in case you don’t want to read the article. LOL.

如果您不想阅读本文,请使用以下代码。 大声笑。

from easyfacenet.simple import facenet

images = ['images/image1.jpg', 'images/image2.jpg', 'images/image3.jpg']
aligned = facenet.align_face(images)
comparisons = facenet.compare(aligned)

print("Is image 1 and 2 similar? ", bool(comparisons[0][1]))
print("Is image 1 and 3 similar? ", bool(comparisons[0][2]))

And it will output the following:

它将输出以下内容:

Is image 1 and 2 similar?  True
Is image 1 and 3 similar?  False

Wait, wait. No tensorflow? There is tensorflow of course. For this tutorial, I use an algorithm called Facenet that was developed with tensorflow. And while it is easy enough for me to use Facenet out of the box while coding tensorflow syntax, I don’t think most of you would be comfortable with that.

等等。 没有张量流? 当然有张量流。 在本教程中,我使用由Tensorflow开发的称为Facenet的算法。 虽然我很容易在编码tensorflow语法时立即使用Facenet,但我认为大多数人都不愿意这样做。

So, I decided to create another interface on top of Facenet, which I called Easy Facenet. To install the library, you can just type

因此,我决定在Facenet之上创建另一个接口,称为Easy Facenet 。 要安装该库,您只需键入

pip install easyfacenet

And you are good to go!

而且你很好走!

The article should not end like this, should it? Of course not.

文章不应该这样结束吗? 当然不是

Let me explain to you, line by line, the tutorial. At the same time, we’ll cover how Face Recognition works in the first place.

让我逐行向您解释该教程。 同时,我们将首先介绍人脸识别的工作原理。

人脸识别 (Face Recognition)

So, how does Face Recognition work?

那么,人脸识别如何工作?

As you can see from the picture above, the steps are like this:

从上图可以看到,步骤是这样的:

  1. Get an input image which should contain a face(s)

    获取应包含面部输入图像

  2. You need to find where exactly the face is and put a bounding box around the face

    您需要找到面部的确切位置,并在面部周围放置一个边界框

  3. For consistency of the algorithm, you need to transform the picture, so that the position of mouth, nose, and eyes, are consistent for different pictures.

    为了确保算法的一致性,您需要对图片进行变换 ,以使嘴,鼻子和眼睛的位置对于不同的图片保持一致。

  4. Then crop it

    然后裁剪

  5. Input the cropped picture into the Facenet algorithm, which is a Deep Neural Network.

    将裁剪的图片输入到Facenet算法中,算法是一个深度神经网络。

  6. It will output a vector representation of that face. It was 128-dimensional vector back then, it is 512-dimensional right now.

    它将输出该脸部的矢量表示 。 当时是128维向量,现在是512维。

  7. Then you can do what you want with that representation. You can do classification, clustering, or just use a similarity computation between pictures.

    然后,您可以使用该表示形式执行所需的操作。 您可以进行分类聚类 ,或者仅使用图片之间的相似度 计算

Wow, that was a hell of a lot of stuff. Why is it so difficult? Well, basically you can group those 7 steps into 3 steps, which are,

哇,那真是太多了。 为什么这么难? 好吧,基本上,您可以将这7个步骤分为3个步骤,

  1. Alignment, input an image and output the aligned cropped face

    对齐 ,输入图像并输出对齐的裁切面

  2. Embedding, input the face and output the representation

    嵌入 ,输入面部并输出表示

  3. Comparison, compare those representations — are they similar or not?

    比较 ,比较这些表示形式-它们是否相似?

Because it’s only 3 simple steps, the code should be as simple as that, shouldn’t it?

因为只有3个简单的步骤,所以代码应该就这么简单,不是吗?

Yes, it can be, using easyfacenet.

是的,可以使用easyfacenet

最简单的人脸识别Tensorflow库 (The simplest Face Recognition Tensorflow library available)

Let’s break down the code bit by bit.

让我们逐一分解代码。

from easyfacenet.simple import facenet

Import the facenet file from a simple module. There are three methods you can use inside the file. They are, align_face, embedding, and compare.

从一个简单的模块导入facenet文件。 您可以在文件内部使用三种方法。 它们是align_faceembeddingcompare

Easily, you can tell that each of these methods represents each step for Face Recognition.

可以很容易地看出,这些方法中的每一个都代表面部识别的每个步骤。

images = ['images/image1.jpg', 'images/image2.jpg', 'images/image3.jpg']

Now we can define the images. What are those images? Well, this.

现在我们可以定义图像了。 这些图像是什么? 好吧,

And this.

还有这个

And also this.

还有这个

We got the images. Now the real deal.

我们得到了图像。 现在真正的交易。

步骤1.对齐 (Step 1. Alignment)

aligned = facenet.align_face(images)

The library will try to find the face inside the image and crop the face as well as pre-whiten the face. Prewhitening will make the training easier at training time, so in inference time, you will also need to prewhiten the image.

库将尝试在图像中查找人脸并裁剪人脸,并对人脸进行预增白预加白会使训练时的训练变得容易,因此在推理时,您还需要将图像预加白。

The prewhitened aligned face will look like this.

经过预增白处理的对齐脸部将看起来像这样。

Now, you are ready for the next step. Take a breather and chew slowly!

现在,您已准备好进行下一步。 喘口气,慢慢咀嚼!

步骤2.嵌入 (Step 2. Embeddings)

Wait, wait. I don’t see embeddings in the example above? Well, that’s because the compare method already called embedding inside. If you want to use embedding somehow, use this.

等等。 我在上面的示例中看不到嵌入吗? 嗯,那是因为compare方法已经称为embed inside 。 如果您想以某种方式使用嵌入,请使用它。

embeddings = facenet.embedding(aligned)

The embeddings will look like this:

嵌入将如下所示:

步骤3.比较 (Step 3. Comparison)

comparisons = facenet.compare(aligned)

If you have 3 images, the comparisons variable will have 3 x 3 values. Which are permutations of each image compared to each other. In an example, if you want to get “is image 1 is similar to image 2?”, then

如果您有3张图片,则compares变量将具有3 x 3的值。 哪个是彼此比较的每个图像的排列 。 在示例中,如果要获取“ 图像1是否类似于图像2? “, 然后

print("Is image 1 and 2 similar? ", bool(comparisons[0][1]))

Is image 1 similar to image 3?

图片1与图片3类似吗?

print("Is image 1 and 3 similar? ", bool(comparisons[0][2]))

You didn’t forget already that the array is zero indexed, did you? Haha…

您还没有忘记数组是零索引的,是吗? 哈哈…

And, that’s it. You can get your comparison result just like that. The comparison technique I used is the cosine similarity. You can use any other similarity method you want. You can definitely use another method like clustering or classification. Something like the Siamese Network is the thing you need to look for.

就是这样 。 这样就可以得到比较结果。 我使用的比较技术是余弦相似度 。 您可以使用任何其他想要的相似性方法。 您绝对可以使用其他方法,例如聚类或分类。 您需要寻找像暹罗网络之类的东西。

接下来您该怎么办? (What can you do next?)

As I have said, this is the simplest Face Recognition Tensorflow library available. Therefore you can start to do your thing as quickly as possible.

正如我所说的,这是最简单的人脸识别Tensorflow库。 因此,您可以尽快开始做您的事情。

If you are the hacky one, you can explore the library and create the real Face Recognition Tensorflow code. Take a look at the code here because that is the cornerstone of the library. Furthermore, extend the code or you can create your own functionality.

如果您是位骇客,则可以浏览该库并创建真实的人脸识别Tensorflow代码。 在这里看看代码因为那是库的基石。 此外,扩展代码或您可以创建自己的功能。

最后的想法 (Final Thoughts)

If you want to know about the paper behind this amazing technology, you can look here as well as here.

如果您想了解这项惊人技术背后的论文 ,可以在这里这里查看

In conclusion, utilizing easyfacenet can help you tremendously in creating your face recognition project. Moreover, this Face Recognition library is maintained solely by me. It is easy for you if you want to ask for some kind of functionality.

总之,利用easyfacenet可以极大地帮助您创建人脸识别项目。 而且,这个人脸识别库完全由我自己 维护 如果您想要某种功能,这对您来说很容易。

As for the actual implementation for the other similarity method, I will bring you there in the next tutorial. Due to that reason, I will add the method exclusively inside the library.

至于其他相似性方法的实际实现,我将在下一个教程中带您到那里。 由于这个原因,我将在库中专门添加该方法。

Finally, if you want to read the original article, I originally published this on my blog post here at thedatamage. Of course, you can read many more posts from me there.

最后,如果您想阅读原始文章,我最初将此文章发布在我的博客文章中的datamage上 。 当然,您可以在这里阅读我的更多文章。

翻译自: https://www.freecodecamp.org/news/they-laughed-when-i-said-face-recognition-was-easy-but-it-can-be-6c1d5dd68099/

百度人脸识别 人脸识别模型

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、人脸识别模型 1. DeepFace DeepFace是Facebook人工智能研究团队所开发的一种基于卷积神经网络的人脸识别模型。该模型通过多层卷积神经网络将输入的人脸图像转化为固定长度的向量,再通过向量相似度计算实现对人脸的识别。 2. FaceNet FaceNet是Google人工智能研究团队所开发的一种基于深度学习的人脸识别模型。该模型采用三元组损失函数,将同一人的不同人脸图像映射到嵌入空间中相近的位置,不同人的人脸图像映射到相距较远的位置,从而实现对人脸的识别。 3. Inception-ResNet Inception-ResNet是Google研究团队所开发的一种基于深度学习的人脸识别模型。该模型结合了Inception和ResNet两种架构的优点,采用残差连接和多尺度卷积操作,提高了对不同尺度、不同角度、不同表情的人脸识别能力。 二、人脸识别模型的原理 人脸识别模型的基本原理是将输入的人脸图像转化为固定长度的向量,并通过向量相似度计算实现对人脸的识别。具体实现过程中,一般采用卷积神经网络(CNN)或其他深度学习模型进行特征提取和分类。 在人脸识别任务中,特征提取是关键步骤,其目的是通过将人脸图像映射到高维特征空间中,提取出能够表征人脸独特特征的向量。这些向量具有以下特点: 1. 可判别性:同一人的不同图像之间的向量距离尽可能小,不同人的向量距离尽可能大。 2. 鲁棒性:对人脸姿势、表情、光照等变化具有较强的鲁棒性。 人脸识别模型通过比对输入的特征向量与数据库中保存的特征向量,计算出它们之间的相似度,并基于特定的阈值进行分类决策,从而实现人脸识别。 三、人脸识别模型的优缺点 1. DeepFace优点: a. 高精度:DeepFace在LFW人脸识别数据集上取得了99.35%的准确率。 b. 具有统一性:DeepFace的识别结果不受人脸表情、姿势和光照等因素的影响。 c. 计算效率高:DeepFace可对多张人脸图像同进行识别,具有较高的计算效率。 2. DeepFace缺点: a. 训练数据要求高:DeepFace的训练数据要求非常高,需要准备大量人脸数据集。 b. 计算资源要求高:DeepFace需要大量的计算资源来完成训练和识别任务。 3. FaceNet优点: a. 高度可扩展:FaceNet的特征向量可以很容易地进行比较和检索,具有高度可扩展性。 b. 鲁棒性强:FaceNet的特征向量对人脸姿势、表情、光照等变化具有较强的鲁棒性。 c. 计算效率高:FaceNet可以在移动设备上实现快速的人脸识别。 4. FaceNet缺点: a. 训练数据集要求高:FaceNet的训练需要大量人脸数据集。 b. 计算资源要求高:FaceNet需要大量的计算资源来完成训练和识别任务。 5. Inception-ResNet优点: a. 鲁棒性强:Inception-ResNet对人脸姿势、表情、光照等变化具有较强的鲁棒性。 b. 对小尺寸人脸效果好:Inception-ResNet对小尺寸人脸的识别效果较好。 c. 计算效率高:Inception-ResNet可以在移动设备上实现快速的人脸识别。 6. Inception-ResNet缺点: a. 识别精度较低:相比于DeepFace和FaceNet等模型,Inception-ResNet的识别精度较低。 b. 训练间长:Inception-ResNet的训练需要较长的间。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值