Ubuntu搭建face_recognition环境 经测试OK

https://github.com/ageitgey/face_recognition/blob/master/README_Simplified_Chinese.md

https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf

ubuntu 18.04

 

Ubuntu搭建face_recognition环境 经测试OK_第1张图片

开始之前----------

apt-get update -y
apt-get upgrade -y
sudo apt-get install git

sudo apt-get install aptitude

sudo apt-get install aptitude build-essential
apt-get install build-essential
sudo apt-get install ia32-libs
apt-get install cmake

$ /usr/bin/c++ --version

#cmake --version
cmake version 3.10.2

root@opencv-learn-pc2:~/dlib# apt install python3

root@opencv-learn-pc2:~/dlib# apt install python3-pip
root@opencv-learn-pc2:~/dlib# pip3 install setuptools

root@opencv-learn-pc2:~/dlib# python3 setup.py install --yes USE_AVX_INSTRUCTIONS
The --yes options to dlib's setup.py don't do anything since all these options 
are on by default.  So --yes has been removed.  Do not give it to setup.py.

 

https://github.com/ageitgey/face_recognition/blob/master/Dockerfile#L6-L34

安装依赖包

  # This is a sample Dockerfile you can modify to deploy your own app based on face_recognition
   
  FROM python:3.6-slim-stretch
   
  RUN apt-get -y update
  RUN apt-get install -y --fix-missing \
  build-essential \
  cmake \
  gfortran \
  git \
  wget \
  curl \
  graphicsmagick \
  libgraphicsmagick1-dev \
  libatlas-dev \
  libavcodec-dev \
  libavformat-dev \
  libgtk2.0-dev \
  libjpeg-dev \
  liblapack-dev \
  libswscale-dev \
  pkg-config \
  python3-dev \
  python3-numpy \
  software-properties-common \
  zip \
  && apt-get clean && rm -rf /tmp/* /var/tmp/*
   
  RUN cd ~ && \
  mkdir -p dlib && \
  git clone -b 'v19.9' --single-branch https://github.com/davisking/dlib.git dlib/ && \
  cd dlib/ && \
  python3 setup.py install --yes USE_AVX_INSTRUCTIONS
   
   
  # The rest of this file just runs an example script.
   
  # If you wanted to use this Dockerfile to run your own app instead, maybe you would do this:
  # COPY . /root/your_app_or_whatever
  # RUN cd /root/your_app_or_whatever && \
  # pip3 install -r requirements.txt
  # RUN whatever_command_you_run_to_start_your_app
   
  COPY . /root/face_recognition
  RUN cd /root/face_recognition && \
  pip3 install -r requirements.txt && \
  python3 setup.py install
   
  CMD cd /root/face_recognition/examples && \
 

python3 recognize_faces_in_pictures.py

 

 

上面主要安装了依赖包 cmake gcc python3 pip3等

 

为了避免后面出错  修改swap  必须进行

编译安装会报错"virtual memory exhausted: Cannot allocate memory"

查看内存大小

free -m  

https://www.iteye.com/blog/muchfly-2296506

http://www.21yunwei.com/archives/3344

[root@aliserver var]# mkdir /var/temp
[root@aliserver var]# dd if=/dev/zero of=/var/temp/swap bs=1024 count=1024000  
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 23.1628 s, 45.3 MB/s
[root@aliserver var]# mkswap /var/temp/swap 
mkswap: /var/temp/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=a9ed2b26-f5dd-4f7e-8c8c-0a930e5e477b
[root@aliserver var]# swapon /var/temp/swap 
[root@aliserver var]# free -m
             total       used       free     shared    buffers     cached
Mem:           488        479          9          0          1        385
-/+ buffers/cache:         92        396
Swap:          999          0        999

当然,使用完以后可以考虑取消swap,免得影响性能。可以使用命令:
swapoff /var/temp/swap
取消挂载。

如果需要一直存在swap,请写入分区表,否则系统重启以后swap将取消挂载。写入分区表内容:
/var/temp/swap  swap swap defaults 0 0

 

下面是实战命令:
[root@host ~]# free -m
total used free shared buff/cache available
Mem: 1006 381 190 42 434 427
Swap: 259 94 165
[root@host ~]# dd if=/dev/zero of=/var/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 8.71197 s, 241 MB/s
[root@host ~]# mkswap /var/swap
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=941931fe-683b-4082-a6db-82bb741f77e5
[root@host ~]# mkswap -f /var/swap
mkswap: /var/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=17a9a21e-67d2-4343-b95d-d8958814c334
[root@host ~]# swapon /var/swap
swapon: /var/swap: insecure permissions 0644, 0600 suggested.
[root@host ~]# free -m
total used free shared buff/cache available
Mem: 1006 388 65 42 552 417
Swap: 2259 94 2165
[root@host ~]# cat /proc/swaps
Filename Type Size Used Priority
/swap file 266236 96512 -2
/var/swap file 2047996 0 -3
[root@host ~]# vim /etc/fstab
最后一行添加
/var/swap swap swap defaults 0 0

如果不再需要swap,可以清理该分区:
[root@mysql01 var]# swapoff /var/swap

将 /var/swap 添加到 开机引导中

echo "/var/swap swap swap defaults 0 0" >>/etc/fstab

 

 

下载代码开始编译dlib

git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build; cd build; cmake ..; cmake --build .

等待......

root@opencv-learn-pc2:~# cd dlib/
root@opencv-learn-pc2:~/dlib# ls
build           dlib  examples           MANIFEST.in      README.md  tools
CMakeLists.txt  docs  ISSUE_TEMPLATE.md  python_examples  setup.py

root@opencv-learn-pc2:~/dlib# cd build/
root@opencv-learn-pc2:~/dlib/build# ls
CMakeCache.txt  CMakeFiles
root@opencv-learn-pc2:~/dlib/build# cmake ..
-- The CXX compiler identification is GNU 7.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CMake version: 3.10.2
-- Compiling dlib version: 19.19.99
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
 *****************************************************************************
 *** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ***
 *** Make sure libx11-dev is installed if you want GUI support.            ***
 *** On Ubuntu run: sudo apt-get install libx11-dev                        ***
 *****************************************************************************
-- Searching for BLAS and LAPACK
-- Searching for BLAS and LAPACK
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
 *****************************************************************************
 *** No BLAS library found so using dlib's built in BLAS.  However, if you ***
 *** install an optimized BLAS such as OpenBLAS or the Intel MKL your code ***
 *** will run faster.  On Ubuntu you can install OpenBLAS by executing:    ***
 ***    sudo apt-get install libopenblas-dev liblapack-dev                 ***
 *** Or you can easily install OpenBLAS from source by downloading the     ***
 *** source tar file from http://www.openblas.net, extracting it, and      ***
 *** running:                                                              ***
 ***    make; sudo make install                                            ***
 *****************************************************************************
CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version "7.5")
-- DID NOT FIND CUDA
-- Disabling CUDA support for dlib.  DLIB WILL NOT USE CUDA
-- C++11 activated.
-- Configuring done
-- Generating done
-- Build files have been written to: /root/dlib/build

 

 

Build and install the Python extensions:

cd ..
python3 setup.py install

 

等待......

At this point, you should be able to run python3 and type import dlib successfully.

root@opencv-learn-pc2:~/dlib# which gcc
/usr/bin/gcc
root@opencv-learn-pc2:~/dlib# which g++
/usr/bin/g++

export CC=/usr/bin/gcc
export CXX=/usr/bin/g++  

Then, install this module from pypi using pip3 (or pip2 for Python 2):

最后一步

apt install python-pip

pip3 install face_recognition

等待安装完成。。。

测试

 

root@opencv-learn-pc2:~# python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import face_recognition
>>> exit()



root@opencv-learn-pc2:~/dlib# which face_recognition 
/usr/local/bin/face_recognition

】
root@opencv-learn-pc2:~# mkdir face_recognition
root@opencv-learn-pc2:~# cd face_recognition/
root@opencv-learn-pc2:~/face_recognition# mkdir known_image
root@opencv-learn-pc2:~/face_recognition# mkdir unknown_image
root@opencv-learn-pc2:~/face_recognition# pwd
/root/face_recognition


root@opencv-learn-pc2:~/face_recognition# git clone https://github.com/ageitgey/face_recognition.git
Cloning into 'face_recognition'...
remote: Enumerating objects: 814, done.
remote: Total 814 (delta 0), reused 0 (delta 0), pack-reused 814
Receiving objects: 100% (814/814), 101.43 MiB | 23.86 MiB/s, done.
Resolving deltas: 100% (469/469), done.

root@opencv-learn-pc2:~/face_recognition# ls
face_recognition  known_image  newimage  sample  unknown_image

root@opencv-learn-pc2:~/face_recognition# cd face_recognition/
root@opencv-learn-pc2:~/face_recognition/face_recognition# l
AUTHORS.rst         docs/              Makefile          README_Simplified_Chinese.md  setup.py
CONTRIBUTING.rst    examples/          MANIFEST.in       requirements_dev.txt          tests/
docker-compose.yml  face_recognition/  README_Korean.md  requirements_docs.txt         tox.ini
Dockerfile          HISTORY.rst        README.md         requirements.txt
Dockerfile.gpu      LICENSE            README.rst        setup.cfg
root@opencv-learn-pc2:~/face_recognition/face_recognition# cd examples/
root@opencv-learn-pc2:~/face_recognition/face_recognition/examples# ls
alex-lacamoire.png                             hamilton_clip.mp4
benchmark.py                                   identify_and_draw_boxes_on_faces.py
biden.jpg                                      ipynb_examples
blur_faces_on_webcam.py                        knn_examples
digital_makeup.py                              lin-manuel-miranda.png
face_distance.py                               obama-1080p.jpg
facerec_from_video_file.py                     obama-240p.jpg
facerec_from_webcam_faster.py                  obama2.jpg
facerec_from_webcam_multiprocessing.py         obama-480p.jpg
facerec_from_webcam.py                         obama-720p.jpg
face_recognition_knn.py                        obama.jpg
face_recognition_svm.py                        obama_small.jpg
facerec_on_raspberry_pi.py                     recognize_faces_in_pictures.py
facerec_on_raspberry_pi_Simplified_Chinese.py  short_hamilton_clip.mp4
find_faces_in_batches.py                       two_people.jpg
find_faces_in_picture_cnn.py                   web_service_example.py
find_faces_in_picture.py                       web_service_example_Simplified_Chinese.py
find_facial_features_in_picture.py
root@opencv-learn-pc2:~/face_recognition/face_recognition/examples# cp obama* /root/face_recognition/known_image/
root@opencv-learn-pc2:~/face_recognition/face_recognition/examples# cd ..
root@opencv-learn-pc2:~/face_recognition/face_recognition# ls
AUTHORS.rst         docs              Makefile          README_Simplified_Chinese.md  setup.py
CONTRIBUTING.rst    examples          MANIFEST.in       requirements_dev.txt          tests
docker-compose.yml  face_recognition  README_Korean.md  requirements_docs.txt         tox.ini
Dockerfile          HISTORY.rst       README.md         requirements.txt
Dockerfile.gpu      LICENSE           README.rst        setup.cfg
root@opencv-learn-pc2:~/face_recognition/face_recognition# cd ..
root@opencv-learn-pc2:~/face_recognition# ls
alex-lacamoire.png  biden.jpg  face_recognition  known_image  two_people.jpg  unknown_image

root@opencv-learn-pc2:~/face_recognition# face_recognition  ./known_image/ ./unknown_image/

./unknown_image/biden.jpg,unknown_person
./unknown_image/obama.jpg,obama_small
./unknown_image/obama.jpg,obama2
./unknown_image/obama.jpg,obama-720p
./unknown_image/obama.jpg,obama-240p
./unknown_image/obama.jpg,obama-1080p
./unknown_image/obama.jpg,obama-480p
root@opencv-learn-pc2:~/face_recognition# 

 

耗时十秒左右

测试pass

 

 

安装dlib报错1

root@opencv-learn-pc2:~/dlib# ls
build           dlib.egg-info  ISSUE_TEMPLATE.md  README.md
CMakeLists.txt  docs           MANIFEST.in        setup.py
dlib            examples       python_examples    tools
root@opencv-learn-pc2:~/dlib# sudo python setup.py  install
running install
running bdist_egg
running egg_info
writing dlib.egg-info/PKG-INFO
writing top-level names to dlib.egg-info/top_level.txt
writing dependency_links to dlib.egg-info/dependency_links.txt
package init file 'dlib/__init__.py' not found (or not a regular file)
reading manifest file 'dlib.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'tools/python/build*'
writing manifest file 'dlib.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
Building extension for Python 2.7.17 (default, Nov  7 2019, 10:07:09) 
Invoking CMake setup: 'cmake /root/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/root/dlib/build/lib.linux-x86_64-2.7 -DPYTHON_EXECUTABLE=/usr/bin/python -DCMAKE_BUILD_TYPE=Release'
-- pybind11 v2.2.2
-- Using CMake version: 3.10.2
-- Compiling dlib version: 19.19.99
-- SSE4 instructions can be executed by the host processor.
-- AVX instructions can be executed by the host processor.
-- Enabling AVX instructions
-- C++11 activated.
-- Configuring done
-- Generating done
-- Build files have been written to: /root/dlib/build/temp.linux-x86_64-2.7
Invoking CMake build: 'cmake --build . --config Release -- -j1'
[  0%] Building CXX object dlib_build/CMakeFiles/dlib.dir/base64/base64_kernel_1.cpp.o
[  1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bigint/bigint_kernel_1.cpp.o
[  1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bigint/bigint_kernel_2.cpp.o
[  2%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bit_stream/bit_stream_kernel_1.cpp.o
[  3%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_1.cpp.o
[  3%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_2.cpp.o
[  4%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_1.cpp.o
[  5%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_2.cpp.o
[  5%] Building CXX object dlib_build/CMakeFiles/dlib.dir/md5/md5_kernel_1.cpp.o
[  6%] Building CXX object dlib_build/CMakeFiles/dlib.dir/tokenizer/tokenizer_kernel_1.cpp.o
[  7%] Building CXX object dlib_build/CMakeFiles/dlib.dir/unicode/unicode.cpp.o
[  7%] Building CXX object dlib_build/CMakeFiles/dlib.dir/data_io/image_dataset_metadata.cpp.o
[  8%] Building CXX object dlib_build/CMakeFiles/dlib.dir/data_io/mnist.cpp.o
[  9%] Building CXX object dlib_build/CMakeFiles/dlib.dir/global_optimization/global_function_search.cpp.o
[  9%] Building CXX object dlib_build/CMakeFiles/dlib.dir/filtering/kalman_filter.cpp.o
In file included from /root/dlib/dlib/filtering/../matrix.h:11:0,
                 from /root/dlib/dlib/filtering/kalman_filter.h:7,
                 from /root/dlib/dlib/filtering/kalman_filter.cpp:6:
/root/dlib/dlib/filtering/../matrix/matrix_la.h: In function ‘long int dlib::svd4(dlib::svd_u_mode, bool, const dlib::matrix_exp&, dlib::matrix&, dlib::matrix&, dlib::matrix&) [with EXP = dlib::matrix_op, dlib::row_major_layout> > > > >; long int qN = 1; long int qX = 1; long int uM = 1; long int uN = 1; long int vM = 2; long int vN = 1; MM1 = dlib::memory_manager_stateless_kernel_1; MM2 = dlib::memory_manager_stateless_kernel_1; MM3 = dlib::memory_manager_stateless_kernel_1; L1 = dlib::row_major_layout]’:
/root/dlib/dlib/filtering/../matrix/matrix_la.h:225:32: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
             y = abs(q(i)) + abs(e(i));
                             ~~~^~~~~~
/root/dlib/dlib/filtering/../matrix/matrix_la.h:163:20: note: within this loop
         for (i=0; i                    ~^~
[ 10%] Building CXX object dlib_build/CMakeFiles/dlib.dir/test_for_odr_violations.cpp.o
[ 11%] Building CXX object dlib_build/CMakeFiles/dlib.dir/svm/auto.cpp.o
[ 11%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockets/sockets_kernel_1.cpp.o
[ 12%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bsp/bsp.cpp.o
[ 13%] Building CXX object dlib_build/CMakeFiles/dlib.dir/dir_nav/dir_nav_kernel_1.cpp.o
[ 13%] Building CXX object dlib_build/CMakeFiles/dlib.dir/dir_nav/dir_nav_kernel_2.cpp.o
[ 14%] Building CXX object dlib_build/CMakeFiles/dlib.dir/dir_nav/dir_nav_extensions.cpp.o
[ 15%] Building CXX object dlib_build/CMakeFiles/dlib.dir/linker/linker_kernel_1.cpp.o
[ 15%] Building CXX object dlib_build/CMakeFiles/dlib.dir/logger/extra_logger_headers.cpp.o
[ 16%] Building CXX object dlib_build/CMakeFiles/dlib.dir/logger/logger_kernel_1.cpp.o
[ 16%] Building CXX object dlib_build/CMakeFiles/dlib.dir/logger/logger_config_file.cpp.o
[ 17%] Building CXX object dlib_build/CMakeFiles/dlib.dir/misc_api/misc_api_kernel_1.cpp.o
[ 18%] Building CXX object dlib_build/CMakeFiles/dlib.dir/misc_api/misc_api_kernel_2.cpp.o
[ 18%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockets/sockets_extensions.cpp.o
[ 19%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockets/sockets_kernel_2.cpp.o
[ 20%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockstreambuf/sockstreambuf.cpp.o
[ 20%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockstreambuf/sockstreambuf_unbuffered.cpp.o
[ 21%] Building CXX object dlib_build/CMakeFiles/dlib.dir/server/server_kernel.cpp.o
[ 22%] Building CXX object dlib_build/CMakeFiles/dlib.dir/server/server_iostream.cpp.o
[ 22%] Building CXX object dlib_build/CMakeFiles/dlib.dir/server/server_http.cpp.o
[ 23%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/multithreaded_object_extension.cpp.o
[ 24%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threaded_object_extension.cpp.o
[ 24%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threads_kernel_1.cpp.o
[ 25%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threads_kernel_2.cpp.o
[ 26%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threads_kernel_shared.cpp.o
[ 26%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/thread_pool_extension.cpp.o
[ 27%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/async.cpp.o
[ 28%] Building CXX object dlib_build/CMakeFiles/dlib.dir/timer/timer.cpp.o
[ 28%] Building CXX object dlib_build/CMakeFiles/dlib.dir/stack_trace.cpp.o
[ 29%] Building CXX object dlib_build/CMakeFiles/dlib.dir/cuda/cpu_dlib.cpp.o
[ 30%] Building CXX object dlib_build/CMakeFiles/dlib.dir/cuda/tensor_tools.cpp.o
[ 30%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/arm/arm_init.c.o
[ 31%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/arm/filter_neon_intrinsics.c.o
[ 32%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/png.c.o
[ 32%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngerror.c.o
[ 33%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngget.c.o
[ 33%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngmem.c.o
[ 34%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngpread.c.o
[ 35%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngread.c.o
[ 35%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngrio.c.o
[ 36%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngrtran.c.o
[ 37%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngrutil.c.o
[ 37%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngset.c.o
[ 38%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngtrans.c.o
[ 39%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngwio.c.o
[ 39%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngwrite.c.o
[ 40%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngwtran.c.o
[ 41%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libpng/pngwutil.c.o
[ 41%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/adler32.c.o
[ 42%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/compress.c.o
[ 43%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/crc32.c.o
[ 43%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/deflate.c.o
[ 44%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/gzclose.c.o
[ 45%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/gzlib.c.o
[ 45%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/gzread.c.o
[ 46%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/gzwrite.c.o
[ 47%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/infback.c.o
[ 47%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/inffast.c.o
[ 48%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/inflate.c.o
[ 49%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/inftrees.c.o
[ 49%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/trees.c.o
[ 50%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/uncompr.c.o
[ 50%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/zutil.c.o
[ 51%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_loader/png_loader.cpp.o
[ 52%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_saver/save_png.cpp.o
[ 52%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jaricom.c.o
[ 53%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcapimin.c.o
[ 54%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcapistd.c.o
[ 54%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcarith.c.o
[ 55%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jccoefct.c.o
[ 56%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jccolor.c.o
[ 56%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcdctmgr.c.o
[ 57%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jchuff.c.o
[ 58%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcinit.c.o
[ 58%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcmainct.c.o
[ 59%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcmarker.c.o
[ 60%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcmaster.c.o
[ 60%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcomapi.c.o
[ 61%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcparam.c.o
[ 62%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcprepct.c.o
[ 62%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jcsample.c.o
[ 63%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdapimin.c.o
[ 64%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdapistd.c.o
[ 64%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdarith.c.o
[ 65%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdatadst.c.o
[ 66%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdatasrc.c.o
[ 66%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdcoefct.c.o
[ 67%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdcolor.c.o
[ 67%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jddctmgr.c.o
[ 68%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdhuff.c.o
[ 69%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdinput.c.o
[ 69%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdmainct.c.o
[ 70%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdmarker.c.o
[ 71%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdmaster.c.o
[ 71%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdmerge.c.o
[ 72%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdpostct.c.o
[ 73%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jdsample.c.o
[ 73%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jerror.c.o
[ 74%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jfdctflt.c.o
[ 75%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jfdctfst.c.o
[ 75%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jfdctint.c.o
[ 76%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jidctflt.c.o
[ 77%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jidctfst.c.o
[ 77%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jidctint.c.o
[ 78%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jmemmgr.c.o
[ 79%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jmemnobs.c.o
[ 79%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jquant1.c.o
[ 80%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jquant2.c.o
[ 81%] Building C object dlib_build/CMakeFiles/dlib.dir/external/libjpeg/jutils.c.o
[ 81%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_loader/jpeg_loader.cpp.o
[ 82%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_saver/save_jpeg.cpp.o
[ 83%] Linking CXX static library libdlib.a
[ 83%] Built target dlib
[ 83%] Building CXX object CMakeFiles/dlib_python.dir/src/dlib.cpp.o
[ 84%] Building CXX object CMakeFiles/dlib_python.dir/src/matrix.cpp.o
[ 84%] Building CXX object CMakeFiles/dlib_python.dir/src/vector.cpp.o
virtual memory exhausted: Cannot allocate memory
CMakeFiles/dlib_python.dir/build.make:110: recipe for target 'CMakeFiles/dlib_python.dir/src/vector.cpp.o' failed
make[2]: *** [CMakeFiles/dlib_python.dir/src/vector.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/dlib_python.dir/all' failed
make[1]: *** [CMakeFiles/dlib_python.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 261, in
    'Topic :: Software Development',
  File "/usr/lib/python2.7/dist-packages/setuptools/__init__.py", line 129, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/bdist_egg.py", line 172, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/bdist_egg.py", line 158, in call_command
    self.run_command(cmdname)
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install_lib.py", line 24, in run
    self.build()
  File "/usr/lib/python2.7/distutils/command/install_lib.py", line 111, in build
    self.run_command('build_ext')
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "setup.py", line 135, in run
    self.build_extension(ext)
  File "setup.py", line 175, in build_extension
    subprocess.check_call(cmake_build, cwd=build_folder)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '-j1']' returned non-zero exit status 2
 

需要安装gcc cmake和build-essential   python3   pip3

错误2

root@opencv-learn-pc2:~/dlib# pip install face_recognition
Collecting face_recognition
  Downloading https://files.pythonhosted.org/packages/3f/ed/ad9a28042f373d4633fc8b49109b623597d6f193d3bbbef7780a5ee8eef2/face_recognition-1.2.3-py2.py3-none-any.whl
Collecting numpy (from face_recognition)
  Downloading https://files.pythonhosted.org/packages/d7/b1/3367ea1f372957f97a6752ec725b87886e12af1415216feec9067e31df70/numpy-1.16.5-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)
    100% |████████████████████████████████| 17.0MB 53kB/s 
Collecting Click>=6.0 (from face_recognition)
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
    100% |████████████████████████████████| 81kB 7.5MB/s 
Collecting face-recognition-models>=0.3.0 (from face_recognition)
  Downloading https://files.pythonhosted.org/packages/cf/3b/4fd8c534f6c0d1b80ce0973d01331525538045084c73c153ee6df20224cf/face_recognition_models-0.3.0.tar.gz (100.1MB)
    99% |████████████████████████████████| 100.1MB 41.8MB/s eta 0:00:01Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 821, in unpack_url
    hashes=hashes
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 659, in unpack_http_url
    hashes)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 603, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "/usr/lib/python2.7/dist-packages/pip/utils/hashes.py", line 46, in check_against_chunks
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 571, in written_chunks
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/pip/utils/ui.py", line 139, in iter
    for x in it:
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 560, in resp_read
    decode_content=False):
  File "/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/response.py", line 436, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/response.py", line 384, in read
    data = self._fp.read(amt)
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/filewrapper.py", line 63, in read
    self._close()
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/filewrapper.py", line 50, in _close
    self.__callback(self.__buf.getvalue())
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/controller.py", line 275, in cache_response
    self.serializer.dumps(request, response, body=body),
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/serialize.py", line 55, in dumps
    "body": _b64_encode_bytes(body),
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/serialize.py", line 12, in _b64_encode_bytes
    return base64.b64encode(b).decode("ascii")
MemoryError
 

按照前面的步骤扩展swap即可解决

 

 

如果你遇到了幺蛾子,可以用Ubuntu虚拟机安装本项目,看下面这个教程。 如何使用Adam Geitgey大神提供的Ubuntu虚拟机镜像文件安装配置虚拟机,本项目已经包含在镜像中.

在 Mac 或者 Linux上安装本项目 2

修改你的pip镜像源为清华镜像,然后使用pip install face_recognition,可以自动帮你安装各种依赖,包括dlib。只是在安装dlib的时候可能会出问题,因为dlib需要编译,出现的问题一般是gcc或者g++版本的问题,所以在pip install face_recognition之前,可以通过在命令行键入

export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++  

来指定你gcc和g++对应的位置,(这两句话会临时修改当前终端的环境变量/usr/local/bin/gcc对应你自己gcc或者g++所在目录)。

 

你可能感兴趣的:(MACOS开发笔记,机器视觉)