python - 当我将 [0] 添加到 face_encodings 时,如何修复 IndexError:列表索引超出范围?
问题描述
我正在尝试学习人脸识别,并在 google colab 和 jupyter notebook 上都尝试过,当我编写添加索引 [0] 的写入方式时,我得到一个 IndexError: list index out of range 但它没有给出错误时我省略了 [0],在这种情况下,当我尝试比较人脸时会出现另一个错误。这是我的错误的样子
() 中的 IndexError Traceback(最近一次调用最后一次)
2 for file in os.listdir(known_dir):
3 img = read_img(known_dir + '/' + file)
----> 4 img_enc = face_recognition.face_encodings(img)[0]
5 known_encodings.append(img_enc)
6 known_names.append(file.split('.')[0])
IndexError:列表索引超出范围
这是我的代码
known_dir = '/content/drive/My Drive/Colab Notebooks/behic_faces'
for file in os.listdir(known_dir):
img = read_img(known_dir + '/' + file)
img_enc = face_recognition.face_encodings(img)[0]
known_encodings.append(img_enc)
known_names.append(file.split('.')[0])
解决方案
推荐阅读
- reactjs - 如何使我的 React 应用程序安全?到目前为止,我可以使用 React DOM 工具登录,我错过了什么?
- javascript - 使用 lodash 格式化数据
- bootstrap-4 - Bootstrap BuildTools - 捆绑安装 - 找不到 Gemfile
- reactjs - 无法使用 SSR 路由呈现页面
- c# - 请解释信号量计数方案
- java - 触控板滚动在 JScrollPane 中不起作用
- python - 如何从嵌套字典的键构建路径?
- constraints - 我需要限制不应跨越 4k 边界的数据包
- c# - 从列表中删除数据
- r - 删除目录中所有 txt 文件低于阈值的行