> For the complete documentation index, see [llms.txt](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-si-men-ke-juan-ji-shen-jing-wang-luo-convolutional-neural-networks/convolutional-neural-networks/special-applications/42-one-shotxue-xi-ff08-one-shot-learning.md).

# 4.2 One-Shot学习（One-shot learning）

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/8b3b58571307fce29dbced077bd86ea7.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/8b3b58571307fce29dbced077bd86ea7.png)

要让人脸识别能够做到一次学习，要做的是学习**Similarity**函数

让神经网络学习用$$d$$表示的函数：

$$
d(img1,img2) = degree\ of\ difference\ between\ images
$$

以两张图片作为输入，然后输出这两张图片的差异值

* 如果这两张图片的差异值小于某个阈值$$\tau$$，就能预测这两张图片是同一个人
* 如果差异值大于τ，就能预测这是不同的两个人

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/f46e9ff3ef4819665b487a81784ab821.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/f46e9ff3ef4819665b487a81784ab821.png)

对于人脸识别问题，只需计算测试图片与数据库中K个目标的相似函数，取其中d(img1,img2)最小的目标为匹配对象。若所有的d(img1,img2)都很大，则表示数据库没有这个人

如果之后有新人加入了团队（编号5），只需将他的照片加入数据库，系统依然能照常工作
