再利用face_recognition做人脸识别的时候训练人脸图片时报错:

face_recognition IndexError: list index out of range

主要代码定位到:增加编码到训练集的face_recognition.face_encodings(...)

   #遍历训练集中每个数据集for class_dir in os.listdir(train_dir):if not os.path.isdir(os.path.join(train_dir,class_dir)):continueprint "get:",class_dir#遍历每个目录下的每张照片for img_path in image_files_in_folder(os.path.join(train_dir,class_dir)):image = fr.load_image_file(img_path)boxes = fr.face_locations(image)#对于当前图片 增加编码到训练集X.append(fr.face_encodings(image,known_face_locations=boxes)[0])y.append(class_dir)

分析原因:

在追加数据到X中时,会将识别的图片编码,但是前提是能识别出人脸,否则编码数据则为空,这也为什么会报访问超出边界BUG,这里我们需要添加判断。

   #遍历训练集中每个数据集for class_dir in os.listdir(train_dir):if not os.path.isdir(os.path.join(train_dir,class_dir)):continueprint "get:",class_dir#遍历每个目录下的每张照片for img_path in image_files_in_folder(os.path.join(train_dir,class_dir)):image = fr.load_image_file(img_path)boxes = fr.face_locations(image)#对于当前图片 增加编码到训练集encodings = fr.face_encodings(image,known_face_locations=boxes)if len(encodings) > 0:X.append(encodings[0])y.append(class_dir)else:print("No faces found in the image!")#X.append(fr.face_encodings(image,known_face_locations=boxes)[0])#y.append(class_dir)

face_recognition IndexError: list index out of range相关推荐

  1. face_recognition.face_encodings() 错误提示:IndexError: list index out of range

    今天在用face_recognition进行人脸识别代码执行时遇到一个报错信息:IndexError: list index out of range. 这个错误信息是在执行代码这条语句中出现的: i ...

  2. IndexError: list index out of range的解决办法

    IndexError: list index out of range的解决办法 列表的索引也就是他的元素的个数是没有你所想要找的元素位置,比如这个列表只有十个元素你要找第11个元素这个肯定找不到 解 ...

  3. 爬虫时出现 IndexError: list index out of range 的原因

    爬虫时出现 IndexError: list index out of range 的原因有两种: 简单举例如下: 第一种情况: index越界 Alex = [1,2,3] Alex[1] 2 Al ...

  4. 很有必要看,这篇 解决 IndexError: list index out of range

    运行逻辑回归代码,遭遇bug: Traceback (most recent call last):File "D:/DTLFolder/paperTest/Paper_logistic r ...

  5. mmdetection训练出现:IndexError: list index out of range 错误

    mmdetection训练出现:IndexError: list index out of range 错误 文章目录: 1 问题分析 1.1 尝试解决错误:第一次 1.2 尝试解决错误:第二次 2 ...

  6. 成功解决pml.Simple derived_col_names[int(obj[‘split_feature‘])],\ IndexError: list index out of range

    成功解决pml.SimplePredicate(field=xgboostToPmml.replace_name_with_derivedColumnNames(derived_col_names[i ...

  7. 成功解决.append方法出现错误IndexError: list index out of range

    成功解决.append方法出现错误IndexError: list index out of range 目录 解决问题 解决方法 解决问题 .append方法出现错误IndexError: list ...

  8. 成功解决sys.argv[1] IndexError: list index out of range错误

    成功解决sys.argv[1] IndexError: list index out of range错误 目录 解决问题 解决思路 解决办法 解决问题 sys.argv[1] IndexError: ...

  9. YunYang1994/tensorflow-yolov3 IndexError: list index out of range 解决办法

    YunYang1994/tensorflow-yolov3 IndexError: list index out of range 解决办法 原项目地址:YunYang1994/tensorflow- ...

最新文章

  1. 设计模式理解:工厂模式,抽象工厂,原型方法
  2. 2pin接口耳机_悦耳好音质,续航10小时,用了小米生态链这款耳机,扔掉其它吧...
  3. Opencv3编程入门学习笔记(五)之通道分离(split)与合并(merge)
  4. 企业生产经营相关英文及缩写之(11)--Genenic 普通书写
  5. MFC界面库BCGControlBar v25.3新版亮点:Dialogs和Forms
  6. python3.6,--登录知乎
  7. php curl如何解决分页,一段PHP的分页程序,报错,该如何解决
  8. linux中ps ef和aux,Linux中ps aux、ps -aux、ps -ef之间的区别讲解
  9. 智能摄像机的网络安全如何保障?
  10. Keras——用Keras搭建自编码神经网络(AutoEncoder)
  11. Security+ 学习笔记5 常见的网络攻击
  12. 小试牛刀--编程实现获取计算机的IP地址和计算机名
  13. fabric1.0 java sdk_运行 fabric-sdk-java 官方示例
  14. unity自带的方法
  15. 麒麟LINUX(飞腾ARM)更新软件源
  16. JxBrowser做爬虫时处理浏览器对话框
  17. 《上海悠悠接口自动化平台》-5.测试计划与定时任务
  18. 贴片钽电容封装及规格参数资料
  19. halo输入QQ号获取QQ头像和名称
  20. 如何获取股票交易数据接口?

热门文章

  1. HTML视频学习教程,让你实战入门前端
  2. 年度规划复盘及一些收获
  3. 【2021情人节主题征文】| 写了一个表白网页后,我跟女神在一起啦
  4. winSCP:无权访问。 错误码:3 服务器返回的错误消息:Permission denied解决方案
  5. 戴尔服务器能用大白菜装系统吗,戴尔如何用u盘装系统xp
  6. python 将base64字符串还原成图片保存
  7. 磕磕碰碰的Chrome之plugin开发
  8. SIGIR2020推荐系统论文解析:Recommendation for New Users and New Items
  9. laravel 教程链接
  10. 推荐系统工程系列(1):浅谈推荐系统架构