找回密码
 立即注册
lilacbeauty 该用户已被删除
发表于 2019-8-4 05:44:13
10791
分别在PC机(Ubuntu 16.04)上、Xavier(Jetpack4.2.1)上和Nano(Jetpack4.2.1)上运行同样的代码。
PC机和Xavier是一样的正常的结果,如图1所示。Nano结果异常,如图2所示。

就是一个应用dlib做人脸识别的简单代码,感觉是numpy.linalg.norm()这个计算范数的函数在Nano上有bug。
代码段如下所示,请教下各位大佬应该这个问题可能是什么原因导致的,应该如何解决呢?

#-*- coding:utf-8 -*-
import dlib
import os
import numpy

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
facerec = dlib.face_recognition_model_v1('dlib_face_recognition_resnet_model_v1.dat')

def create_known(known_path):
    person_names = []
    face_features = []

    print("Creating Known Face Library...")
    for file_name in os.listdir(known_path):
        if (file_name.find('png')<0) and (file_name.find('jpg')<0):
            continue

        img = dlib.load_rgb_image(os.path.join(known_path,file_name))
        dets = detector(img)
        if (len(dets) == 0):
            continue

        det = dets[0]
        shape = predictor(img, det)
        descriptor = facerec.compute_face_descriptor(img, shape)

        person_name = file_name[:file_name.rfind('.')]
        person_names.append(person_name)
        face_features.append(descriptor)
        print('Appending [' + person_name + '] ...')

        dlib.hit_enter_to_continue()

    return person_names, face_features

if __name__ == "__main__":
    person_names, face_features = create_known('known')
    img = dlib.load_rgb_image('nina_victory.jpg')

    dets = detector(img)
    for det in dets:
        shape = predictor(img, det)
        descriptor = facerec.compute_face_descriptor(img, shape)

        min_dist = 1.0
        person_name = 'unknown'
        for i in range(len(face_features)):
            dist = numpy.linalg.norm(numpy.array(descriptor)-numpy.array(face_features[i]))
            print(person_names[i], dist)
            if dist < min_dist:
                min_dist = dist
                person_name = person_names[i]
        print('Found [' + person_name + '] !')

        dlib.hit_enter_to_continue()


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用道具 举报 回复
发表于 2019-8-4 06:30:20
补充一下,第二张图上错了,我后来在Nano上和xavier统一了numpy以及dlib的版本,结果仍然有问题。
可惜回复里不能上图……帖子还不能删了重发……发结果文本吧。


  1. nvidia@nvidia:~/workspace/facereg$ python test_facereg.py
  2. Creating Known Face Library...
  3. Appending [nina] ...
  4. Hit enter to continue
  5. Appending [lidandan] ...
  6. Hit enter to continue
  7. Appending [vitory] ...
  8. Hit enter to continue
  9. ('nina', 2.7818110035028154e+24)
  10. ('lidandan', 2.781277577877308e+24)
  11. ('vitory', 1.1984561081838429e+25)
  12. Found [unknown] !
  13. Hit enter to continue
  14. ('nina', nan)
  15. ('lidandan', nan)
  16. ('vitory', nan)
  17. Found [unknown] !
  18. Hit enter to continue
  19. nvidia@nvidia:~/workspace/facereg$ python
  20. Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
  21. [GCC 7.3.0] on linux2
  22. Type "help", "copyright", "credits" or "license" for more information.
  23. >>> import numpy
  24. >>> numpy.__version__
  25. '1.14.0'
  26. >>> import dlib
  27. >>> dlib.__version__
  28. u'19.17.0'
  29. >>>
复制代码
使用道具 举报 回复 支持 反对
发新帖
您需要登录后才可以回帖 登录 | 立即注册

zzczczxczxczx