numpy.AxisError:轴1超出维度1的数组的边界

时间:2019-04-28 13:47:18

标签: python numpy face-recognition

这是我的代码。我正在使用face_recognition库。从数据库中获取face_encoding时。在for循环的第二次迭代中出现一些错误。


for each in rows:
    face_data = pickle.loads(each[0])

    for (top, right, bottom, left), face_encoding in zip(face_locations, face_encoding):
        print(face_data)
        matches = face_recognition.compare_faces([face_encoding], face_data)

        if True in matches:
            print(f'Face matches with {each[1]}')
            break

        else:
            print('Face does not match')

这是我的执行顺序

[-0.07152465  0.10215988  0.01136428 -0.0308747  -0.16287753 -0.03153189
 -0.06578728 -0.14805837  0.15640661 -0.07523477  0.14867496  0.04072035
 -0.16808468 -0.00982519 -0.02270632  0.08025806 -0.20561409 -0.12184067
 -0.11708203 -0.09774955 -0.06495257  0.02422624  0.00922573  0.01991012
 -0.13370116 -0.20686181 -0.1488608  -0.12282808  0.18252769 -0.08956295
  0.0171157   0.07873753 -0.1460952  -0.09000996  0.06861175  0.13834456
 -0.07108913 -0.01959831  0.20239949  0.05026209 -0.15374154 -0.01580941
  0.06390329  0.27492422  0.25704402  0.08602936  0.03448958 -0.04159172
  0.14044689 -0.21021228  0.06922252  0.15272671  0.21329369  0.10292344
  0.08227161 -0.22346584  0.09088185  0.14461374 -0.1744801   0.11717336
  0.13315231 -0.16698143  0.00260702  0.07305491  0.18898451  0.10911863
 -0.01746466 -0.16348183  0.23652273 -0.22252038 -0.06905969  0.12435962
 -0.07139365 -0.08369306 -0.24058753 -0.06713018  0.39160824  0.16331878
 -0.09675828 -0.01672895 -0.0439845  -0.05550656  0.00398231  0.04980896
 -0.17432253 -0.07968439 -0.12069637 -0.02069626  0.22844598 -0.00178664
  0.06633241  0.1762405   0.02624917 -0.00859033  0.03681781 -0.02436156
 -0.13713233 -0.03320267 -0.03164122 -0.09198754  0.03632114 -0.15644331
  0.04891206  0.11745825 -0.20992307  0.17861255 -0.07077605  0.00281386
 -0.03633321 -0.04432689 -0.02048816  0.02499891  0.28510362 -0.21085122
  0.21044926  0.21076941 -0.06554883  0.08499552  0.05917196  0.1140425
 -0.05485246 -0.04627831 -0.15220977 -0.10018148 -0.06419093 -0.15043713
  0.02276208  0.0441333 ]

Face does not match

[-0.09625021  0.14334008  0.04706059 -0.04014181 -0.08584346 -0.01887352
  0.00490261 -0.1639722   0.09984879 -0.15265316  0.20287979 -0.04864441
 -0.32042649 -0.09799721 -0.00439703  0.14766732 -0.14317626 -0.07932805
 -0.15182969 -0.12430412  0.06176512  0.09200086 -0.01968544 -0.04486096
 -0.10424317 -0.2421699  -0.08235801 -0.06906197  0.02620533 -0.09016494
  0.03978066  0.03132563 -0.16744252 -0.04149911 -0.04274801  0.04262511
 -0.06783581 -0.06297266  0.08989972  0.00187942 -0.13782793 -0.02583435
 -0.02318384  0.22219715  0.21874472 -0.00792544  0.01723921 -0.13756718
  0.12533604 -0.23840009 -0.01863693  0.0764866   0.05697979  0.10692431
  0.03860043 -0.14166503  0.02846308  0.13315612 -0.17089525  0.05577727
  0.06003947 -0.2250281  -0.06753878 -0.01277698  0.08528464  0.04355494
 -0.0524184  -0.13549563  0.25745231 -0.17983361 -0.11317196  0.03724971
 -0.05688772 -0.14536679 -0.33049241  0.00788163  0.37128115  0.1440357
 -0.17786828 -0.03610786 -0.03851928  0.00788332  0.10840025  0.08781973
 -0.0197401  -0.11310805 -0.12882231  0.05047181  0.22589801 -0.1145445
 -0.02849352  0.24946831  0.02767072  0.01063228  0.03616182  0.05806186
 -0.100531    0.00592576 -0.07722946 -0.0200903   0.09955086 -0.16360769
 -0.02626547  0.12187837 -0.10974941  0.25797191  0.01019638  0.00796576
 -0.01505023 -0.11661487 -0.02455078  0.05865026  0.19031769 -0.1405995
  0.22529884  0.2284973  -0.00063039  0.16232219  0.03971991  0.09476222
 -0.03303688 -0.08237147 -0.22452414 -0.15178023  0.02300116  0.01437929
 -0.01491559  0.04098029]

Traceback (most recent call last):
  File "set_faces.py", line 33, in <module>
    matches = face_recognition.compare_faces([face_encoding], face_data)
  File "/home/dipanshuchaubey/.local/share/virtualenvs/face_recog-byiVijNu/lib/python3.6/site-packages/face_recognition/api.py", line 222, in compare_faces
    return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance)
  File "/home/dipanshuchaubey/.local/share/virtualenvs/face_recog-byiVijNu/lib/python3.6/site-packages/face_recognition/api.py", line 72, in face_distance
    return np.linalg.norm(face_encodings - face_to_compare, axis=1)
  File "/home/dipanshuchaubey/.local/share/virtualenvs/face_recog-byiVijNu/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 2481, in norm
    return sqrt(add.reduce(s, axis=axis, keepdims=keepdims))

numpy.AxisError: axis 1 is out of bounds for array of dimension 1

似乎一切正常,直到第一次迭代。为什么在第二次迭代中出现此错误?

谢谢。

0 个答案:

没有答案