将库运行到 python 时出错 [英] Error to run a library to python
问题描述
我按照http://npatta01.github.io/2015的步骤/08/10/dlib/ 但是当我尝试运行时(我使用 sudo),
python python_examples/face_detector.py examples/faces/2007_007763.jpg
收回错误.首先,错误是
AttributeError: 'module' 对象没有属性 'image_window'
到第 8 行.现在,错误是 Illegal instructions (core dumped)
但我不知道为什么.请帮我正确添加库.
导入系统导入数据库从 skimage 导入 io检测器 = dlib.get_frontal_face_detector()赢 = dlib.image_window()对于 sys.argv[1:] 中的 f:print("处理文件:{}".format(f))img = io.imread(f)# 第二个参数中的 1 表示我们应该对图像进行上采样# 1次.这将使一切变得更大,并使我们能够检测到更多# 脸.dets = 检测器(img, 1)print("检测到的人脸数量:{}".format(len(dets)))对于 enumerate(dets) 中的 i, d:打印(检测{}:左:{}顶部:{}右:{}底部:{}".格式(i, d.left(), d.top(), d.right(), d.bottom()))win.clear_overlay()win.set_image(img)win.add_overlay(dets)dlib.hit_enter_to_continue()# 最后,如果你真的想要你可以让检测器告诉你分数# 每次检测.对于更可靠的检测,分数更大.# 运行的第三个参数是对检测阈值的可选调整,# 其中负值将返回更多检测,而正值将返回更少.# 另外,idx 会告诉您匹配了哪些人脸子检测器.这可以# 用于广泛识别不同方向的人脸.如果 (len(sys.argv[1:]) > 0):img = io.imread(sys.argv[1])dets, 分数, idx =detector.run(img, 1, -1)对于 enumerate(dets) 中的 i, d:打印(检测{},分数:{},face_type:{}".格式(d, 分数[i], idx[i]))
我回答这个问题是因为我在做
时遇到了同样的问题conda install -c conda-forge dlib
和
pip install dlib
我尝试搜索并获得了几个有用的链接,下面的一个链接拯救了我的一天.所以也在这里列出详细信息..
https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928ae> 从 Github 编译最新代码比从 conda/pip 安装要好.这是为了确保 dlib 是在 GUI 支持下编译的. 安装依赖 安装 Boost 安装其他依赖项(可能大部分已经安装在你的系统中) 从 Github 构建最新的 dlib 代码.假设:- Ubuntu 16.04 或更高版本- 没有 nVidia GPU,没有安装 Cuda 和 cuDNN,也不想 GPU 加速 从github克隆代码: 构建主 dlib 库: 构建并安装 Python 扩展: 确保指向正确的 python(如果你在 Ubuntu 的 vanilla python 之上安装了 anaconda,那么你应该安装指向 anaconda 的包). 如果您仍然面临如下 gcc 错误 然后确保你正在安装下面的python包 此时应该可以运行python并成功输入import dlib. I follow the steps according to http://npatta01.github.io/2015/08/10/dlib/ but when I try to run (I use sudo), take back error.
Firstly, the error was to line 8.
Now, the error is
I am answering this question because I ran into the same issue by doing and I tried searched and got several helpful links and below one link was saved my day. So listing down the details here too.. https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf It will be better to compile the latest code from Github than installing it from conda / pip. This is to ensure that dlib is compiled with GUI support. Install dependencies Install Boost Install other dependencies ( May be most of them will already have installed in your system) Build the latestst code of dlib from Github.
Assumptions:
- Ubuntu 16.04 or higher
- don't have an nVidia GPU and don't have Cuda and cuDNN installed and don't want GPU acceleration Clone the code from github: Build the main dlib library: Build and install the Python extensions: make sure are pointing to the right python( if you have anaconda installed on top of Ubuntu's vanilla python then you should install the package pointing anaconda). if you are still facing a gcc error like below then make sure you are installing the below python package At this point, you should be able to run python and type import dlib successfully. 这篇关于将库运行到 python 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!sudo apt-get update
sudo apt-get install libboost-all-dev
apt-get install -y --fix-missing build-essential cmake gfortran git wget curl graphicsmagick libgraphicsmagick1-dev libatlas-dev libavcodec-dev libavformat-dev libboost-all-dev libgtk2.0-dev libjpeg-dev liblapack-dev libswscale-dev pkg-config python3-dev python3-numpy software-properties-common zip易于清洁
git clone https://github.com/davisking/dlib.git
cd dlibmkdir 构建;光盘构建;cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1;cmake --build .
cd ..python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
lib/libstdc++.so.6:未找到版本GLIBCXX_3.4.21"
conda 安装 libgcc
python python_examples/face_detector.py examples/faces/2007_007763.jpg
AttributeError: 'module' object has no attribute 'image_window'
Illegal instruction (core dumped)
but I don't know why.
Please, help me to add the library correctly. import sys
import dlib
from skimage import io
detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
for f in sys.argv[1:]:
print("Processing file: {}".format(f))
img = io.imread(f)
# 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 i, d in enumerate(dets):
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
i, d.left(), d.top(), d.right(), d.bottom()))
win.clear_overlay()
win.set_image(img)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
# Finally, if you really want to you can ask the detector to tell you the score
# for each detection. The score is bigger for more confident detections.
# The third argument to run is an optional adjustment to the detection threshold,
# where a negative value will return more detections and a positive value fewer.
# Also, the idx tells you which of the face sub-detectors matched. This can be
# used to broadly identify faces in different orientations.
if (len(sys.argv[1:]) > 0):
img = io.imread(sys.argv[1])
dets, scores, idx = detector.run(img, 1, -1)
for i, d in enumerate(dets):
print("Detection {}, score: {}, face_type:{}".format(
d, scores[i], idx[i]))
conda install -c conda-forge dlib
pip install dlib
sudo apt-get update
sudo apt-get install libboost-all-dev
apt-get install -y --fix-missing build-essential cmake gfortran git wget curl graphicsmagick libgraphicsmagick1-dev libatlas-dev libavcodec-dev libavformat-dev libboost-all-dev libgtk2.0-dev libjpeg-dev liblapack-dev libswscale-dev pkg-config python3-dev python3-numpy software-properties-common zip
apt-get clean
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
cd ..
python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
conda install libgcc