深度学习 火焰识别_AI宝宝识人指南深度学习人脸识别

0e63f3a18b625daa5e95c46bac9a9ba0.png 0020f490448e861a908b150d1f79ef02.png 09f57389721006c6e73d88a1ac1e7019.png 本文大致介绍了pillow, dlib,face_recognition 包的安装及使用,以及深度学习中人脸识别的简单运用。 09f57389721006c6e73d88a1ac1e7019.png
  • 环境搭建

  • 简单的人脸识别

环境搭建

Anaconda 、Python 和 Pycharm 的安装和调试本文不做过多的赘述,不太了解的小伙伴可以在上一篇AI宝宝接生指南中看到。 安装 pillow 、face_recognition 包也可参照上一篇文章,如果报错缺失环境文件,建议按照下面步骤先安装Cmake、c++ build tools 和 dlib。 因为用直接安装的方法安装 dlib 很可能会报错,所以这里就简单的介绍一下。 由于dlib包中有c语言编译成分所以安装它的时候系统中必须要有适配的C++编译器。 官网下载: https://visualstudio.microsoft.com/visual-cpp-build-tools/ 422b8c95824e6c160a88a438d9c72ca5.png 下载完成后打开安装包,稍等片刻,进入应用界面后默认勾选红框内的选项,然后点击右下角安装。 友情提示:在工具栏的第三个选项可以安装中文的适配包,安装完成后,会提示需要重启。电脑重启后即可完成安装。 44e5f6ee7d4b4286885ba2321a6ed477.png 42cb0bea97fee95bfe7b1e8ec7853470.png 重启后我们打开Pycharm,新建一个工程文件或 python 文件,或者在 github 上提前下载好需要运行的的代码,然后直接在右下角选取合适的编译环境。 4cf11a1132daeeb276202839e04d03e6.png 打开左下角第三栏的terminal,依次输入以下代码,友情提示这个过程可能会有点慢。
pip install cmakepip install dlibpip install face-recognitionpip install pillow

简单的人脸识别

因为face_reccognition包不支持读取在线的图片文件,所以我们先把要要识别的图片下载到本地目录。
import face_recognitionimport requests#这里的链接你可以改成网上任意的照片链接,只要保证后缀是.jpg或.png计算机可读取即可response = requests.get("https://raw.githubusercontent.com/neowalter/Neural_network/main/pics/MUSK.jpg")file = open("MUSK.jpg", "wb")file.write(response.content)file.close()response = requests.get("https://raw.githubusercontent.com/neowalter/Neural_network/main/pics/MHT.jpg")file = open("MHT.jpg", "wb")file.write(response.content)file.close()response = requests.get("https://raw.githubusercontent.com/neowalter/Neural_network/main/pics/Elon-Musk-2010.jpg")file = open("p3.jpg", "wb")file.write(response.content)file.close()MUSK = face_recognition.load_image_file("MUSK.jpg")MHT = face_recognition.load_image_file("MHT.jpg")# Get the face encoding of each person. This can fail if no one is found in the photo.musk_face_encoding = face_recognition.face_encodings(MUSK)[0]mht_face_encoding = face_recognition.face_encodings(MHT)[0]# Create a list of all known face encodingsknown_face_encodings = [    musk_face_encoding,    mht_face_encoding,]# Load the image we want to checkunknown_image = face_recognition.load_image_file("p3.jpg")# Get face encodings for any people in the pictureface_locations = face_recognition.face_locations(unknown_image, number_of_times_to_upsample=2)unknown_face_encodings = face_recognition.face_encodings(unknown_image, known_face_locations=face_locations)# There might be more than one person in the photo, so we need to loop over each face we foundfor unknown_face_encoding in unknown_face_encodings:    # Test if this unknown face encoding matches any of the three people we know    results = face_recognition.compare_faces(known_face_encodings, unknown_face_encoding, tolerance=0.6)    name = "Unknown"    if results[0]:        name = "MUSK"    elif results[1]:        name = "MHT"    print(f"Found {name} in the photo!")
学习素材 320c36da2acf5fb1e333e12e0f5bd3b9.png 供识别图片 578201dbb3add1e7e14900ab432929f8.png 很好,我们的代码有效的识别出了MUSK! 057989ffbfbbbf6ebbe41180566e4e25.png 感兴趣的朋友也可以用自己的照片来试试 。 5b02cd32dc6d5065ba3ca5e2d573a5a8.png精彩推荐

数据分析的Python之路

IT项目管理

NLP学习笔记

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值