【问题标题】:axis 1 is out of bounds for array of dimension 1轴 1 超出了维度为 1 的数组的范围
【发布时间】:2018-05-22 19:14:57
【问题描述】:

我正在 python 中使用人脸识别。我有一个以下程序来识别我的个人资料。

import face_recognition

# Load some images to compare against
known_image = face_recognition.load_image_file("IMG_2051.JPG")

# Get the face encodings for the known images
face_encoding = face_recognition.face_encodings(known_image)[0]

# Load a test image and get encondings for it
image_to_test = face_recognition.load_image_file("manushi.jpg")
image_to_test_encoding = face_recognition.face_encodings(image_to_test)[0]

# See how far apart the test image is from the known faces
face_distances = face_recognition.face_distance(face_encoding, image_to_test_encoding)

for i, face_distance in enumerate(face_distances):
    print("The test image has a distance of {:.2} from known image #{}".format(face_distance, i))
    print("- With a normal cutoff of 0.6, would the test image match the known image? {}".format(face_distance < 0.6))
    print("- With a very strict cutoff of 0.5, would the test image match the known image? {}".format(face_distance < 0.5))
    print()

但是,我收到以下错误:

Traceback (most recent call last):
  File "test.py", line 14, in <module>
    face_distances = face_recognition.face_distance(face_encoding, image_to_test_encoding)
  File "/usr/local/lib/python2.7/dist-packages/face_recognition/api.py", line 70, in face_distance
    return np.linalg.norm(face_encodings - face_to_compare, axis=1)
  File "/usr/local/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 2198, in norm
    return sqrt(add.reduce(s, axis=axis, keepdims=keepdims))
numpy.core._internal.AxisError: axis 1 is out of bounds for array of dimension 1

请有人帮助我。提前致谢。

【问题讨论】:

    标签: python python-3.x python-2.7 face-detection


    【解决方案1】:

    您的代码几乎是正确的,face_distance 函数将数组作为第一个参数,因此 face_encoding 需要作为数组传递:

    face_distances = face_recognition.face_distance([face_encoding], image_to_test_encoding)

    在 face_recognition github repo 上提供的face_distance sample script 中,您可以看到face_encoding 的输入是一个数组。

    我还测试了将face_encoding 作为数组传递,它可以工作。

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 2020-10-30
      • 2020-07-31
      • 2022-07-03
      相关资源
      最近更新 更多