【问题标题】:Illegal instruction (core dumped) while running Dlib Face detection运行 Dlib 人脸检测时出现非法指令(核心转储)
【发布时间】:2016-10-20 15:29:33
【问题描述】:

我正在尝试运行由Dlib 库提供的 face_landmark_detection.py 示例。

但是当我尝试通过 ubuntu 终端运行命令时出现错误:

Illegal instruction (core dumped)

我调试它,所以我知道这是因为这条线:

win=dlib.image_window()

我猜这行有问题

我正在通过这个命令运行代码:

./face_landmark_detection.py /home/abhishek/openCV/shape_predictor_68_face_landmarks.dat ../examples/faces

正如示例代码中所做的那样。 我的代码

        import sys
        import os
        import dlib
        import glob
        from skimage import io

        if len(sys.argv) != 3:
        print(
    "Give the path to the trained shape predictor model as the first "
    "argument and then the directory containing the facial images.\n"
    "For example, if you are in the python_examples folder then "
    "execute this program by running:\n"
    "    ./face_landmark_detection.py shape_predictor_68_face_landmarks.dat ../examples/faces\n"
    "You can download a trained facial shape predictor from:\n"
    "    http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2")
            exit()

        predictor_path = sys.argv[1]
        faces_folder_path = sys.argv[2]

        print predictor_path
        print faces_folder_path

        detector = dlib.get_frontal_face_detector()
        predictor = dlib.shape_predictor(predictor_path)
        win = dlib.image_window()


        for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")):

             print("Processing file: {}".format(f))
             img = io.imread(f)

             print "img",img
             win.clear_overlay()
             win.set_image(img)

# Ask the detector to find the bounding boxes of each face. The 1 in the
# second argument indicates that we should upsample the image 1 time. This
# will make everything bigger and allow us to detect more faces.
        dets = detector(img, 1)
        print("Number of faces detected: {}".format(len(dets)))
        for k, d in enumerate(dets):
               print("Detection {}: Left: {} Top: {} Right: {} Bottom:             {}".format(
        k, d.left(), d.top(), d.right(), d.bottom()))
    # Get the landmarks/parts for the face in box d.
            shape = predictor(img, d)
            print("Part 0: {}, Part 1: {} ...".format(shape.part(0),
                                              shape.part(1)))
    # Draw the face landmarks on the screen.
           win.add_overlay(shape)

    win.add_overlay(dets)
    dlib.hit_enter_to_continue()

【问题讨论】:

  • 非法教学的常见原因有很多。该文件可能已作为文本而不是二进制文件下载,或者有人将文本编辑器带到可执行文件并将其保存为文本。可能是您使用不兼容的字长运行,例如带有 32 位模块的 64 位 python(反之亦然)。或者,您可以运行来自不同架构的可执行文件,例如 UNIX 平台上的 Windows 二进制文件,或 Intel 上的 Solaris (RISC)。检查您的安装。
  • 至少对于可执行文件,如果您尝试为不同架构运行二进制文件,您宁愿获得exec format errorillegal instruction 也可以来自更微妙的东西,例如使用编译后的二进制文件在不支持此功能的旧处理器(例如,比用于 AVX 的 Sandy Bridge 旧)上使用较新处理器代(例如 AVX)的指令。
  • @cdarke,我已经检查了安装并再次完成了安装。我不认为有任何安装错误。我可能认为,从终端运行可能会导致错误,因为它不支持 GUI。你能告诉如何支持GUI。有些东西是代码无法处理的。

标签: python face-detection coredump dlib


【解决方案1】:

看起来 dlib 无法在您的情况下创建图像窗口。可能的原因 - 不正确的 dlib 安装。正如 Dlib 的文档所述(readme.txt),您应该通过运行 setup.py 来安装它:

COMPILING DLIB Python API
   Before you can run the Python example programs you must compile dlib. Type:
       python setup.py install
   or type
       python setup.py install --yes USE_AVX_INSTRUCTIONS
   if you have a CPU that supports AVX instructions, since this makes some
   things run faster.  

在运行 setup.py 之前,您还需要安装 libx11-dev (sudo apt-get install libx11-dev)

检查安装脚本消息以查看任何可能的错误,如果您看到它们 - 请更新您的问题以描述情况

【讨论】:

    【解决方案2】:

    我刚刚遇到这个问题,这是因为 python 模块是用 SSE4 指令编译的,但我的 CPU 只支持 SSE2。打开 tools/python/CMakeLists.txt 并编辑该行

    set(USE_SSE4_INSTRUCTIONS ON CACHE BOOL "Use SSE4 instructions")
    

    就我而言,我将其更改为

    set(USE_SSE2_INSTRUCTIONS ON CACHE BOOL "Use SSE2 instructions")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-12
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多