IndexError:列表索引超出范围/ Facenet

时间:2019-03-02 10:14:18

标签: python numpy opencv

我正在尝试使用Facenet算法进行人脸识别程序。一切正常,良好的识别性,但是当我因出现此错误而快速移动头部时,程序将退出。

Traceback (most recent call last):
  File "vf.py", line 122, in <module>
    if HumanNames[best_class_indices[0]] == H_i:
IndexError: list index out of range




  for H_i in HumanNames:
       if HumanNames[best_class_indices[0]] == H_i:
       result_names = HumanNames[best_class_indices[0]]
       cv2.putText(frame, result_names, (text_x, text_y),  cv2.FONT_HERSHEY_COMPLEX_SMALL,1, (0, 0, 255), thickness=1, lineType=2)

1 个答案:

答案 0 :(得分:0)

HumanNames中似乎没有存储任何值,如果是这种情况,那么访问列表中的第一项将引发错误。

首先,您应该检查HumanNames数组的大小,并在调试过程中添加以下行:

print(len(HumanNames))
# The rest of the code from the example....