├── LAB.cpp ├── Makefile.config ├── README.md └── compile.sh /LAB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "opencv2/opencv.hpp" 4 | #include "caffe/caffe.hpp" 5 | using namespace std; 6 | using namespace cv; 7 | using namespace caffe; 8 | inline void Copy(const cv::Mat& cv_mat, caffe::Blob& blob) { 9 | blob.Reshape(1, cv_mat.channels(), cv_mat.rows, cv_mat.cols); 10 | if(cv_mat.channels()==1) { 11 | memcpy(blob.mutable_cpu_data(), cv_mat.data, blob.count()*sizeof(float)); 12 | } 13 | else { 14 | std::vector splited_img; 15 | cv::split(cv_mat, splited_img); 16 | for(size_t i=0; i 21 | inline std::vector ToVector(const caffe::Blob& blob) { 22 | std::vector vec(blob.count()); 23 | memcpy(vec.data(), blob.cpu_data(), vec.size()*sizeof(T)); 24 | return vec; 25 | } 26 | 27 | inline std::vector ToPoints(const std::vector& labels) { 28 | std::vector points(labels.size()/2); 29 | for(size_t i=0; i(i, 0)<1E-6) 49 | std.at(i, 0)=1; 50 | } 51 | vector split_img(img.channels()); 52 | split(img, &(split_img[0])); 53 | for(int i=0;i(i, 0), -1*mean.at(i, 0)/std.at(i, 0)); 55 | merge(&(split_img[0]), img.channels(), img); 56 | } 57 | int main(void) { 58 | string FLAGS_model_path="./models/"; 59 | caffe::Caffe::set_mode(caffe::Caffe::CPU); 60 | string imgPath = "./faceImg.jpg"; 61 | caffe::shared_ptr> deep_align; 62 | caffe::shared_ptr> input_blob; 63 | caffe::shared_ptr> output_blob; 64 | deep_align.reset(new Net(FLAGS_model_path+"rel.prototxt", TEST)); 65 | deep_align->CopyTrainedLayersFrom(FLAGS_model_path+"model.bin"); 66 | input_blob=deep_align->blob_by_name("data"); 67 | output_blob=deep_align->blob_by_name("result"); 68 | Mat image=imread(imgPath); 69 | cv::resize(image,image,cv::Size(256,256)); 70 | Mat show = image.clone(); 71 | ConvertImageToGray(image); 72 | image.convertTo(image, CV_32F); 73 | NormalizeImage(image); 74 | Copy(image, *(input_blob)); 75 | deep_align->Forward(); 76 | vector landmark_98pt=ToPoints(ToVector(*(output_blob))); 77 | for(uint i=0; i= 9.0, comment the *_20 and *_21 lines for compatibility. 40 | CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \ 41 | -gencode arch=compute_35,code=sm_35 \ 42 | -gencode arch=compute_50,code=sm_50 \ 43 | -gencode arch=compute_52,code=sm_52 \ 44 | -gencode arch=compute_60,code=sm_60 \ 45 | -gencode arch=compute_61,code=sm_61 \ 46 | -gencode arch=compute_61,code=compute_61 47 | 48 | # BLAS choice: 49 | # atlas for ATLAS (default) 50 | # mkl for MKL 51 | # open for OpenBlas 52 | BLAS := atlas 53 | # Custom (MKL/ATLAS/OpenBLAS) include and lib directories. 54 | # Leave commented to accept the defaults for your choice of BLAS 55 | # (which should work)! 56 | # BLAS_INCLUDE := /media/hans/4ddb33c4-42d9-4544-b7b4-796994f061ce/enviroments/OpenBLAS/include 57 | # BLAS_LIB := /media/hans/4ddb33c4-42d9-4544-b7b4-796994f061ce/enviroments/OpenBLAS/lib 58 | 59 | # Homebrew puts openblas in a directory that is not on the standard search path 60 | # BLAS_INCLUDE := $(shell brew --prefix openblas)/include 61 | # BLAS_LIB := $(shell brew --prefix openblas)/lib 62 | 63 | # This is required only if you will compile the matlab interface. 64 | # MATLAB directory should contain the mex binary in /bin. 65 | # MATLAB_DIR := /usr/local 66 | # MATLAB_DIR := /Applications/MATLAB_R2012b.app 67 | 68 | # NOTE: this is required only if you will compile the python interface. 69 | # We need to be able to find Python.h and numpy/arrayobject.h. 70 | PYTHON_INCLUDE := /usr/include/python2.7 \ 71 | /usr/local/lib/python2.7/dist-packages/numpy/core/include 72 | # Anaconda Python distribution is quite popular. Include path: 73 | # Verify anaconda location, sometimes it's in root. 74 | # ANACONDA_HOME := $(HOME)/anaconda 75 | # PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ 76 | # $(ANACONDA_HOME)/include/python2.7 \ 77 | # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include 78 | 79 | # Uncomment to use Python 3 (default is Python 2) 80 | # PYTHON_LIBRARIES := boost_python3 python3.5m 81 | # PYTHON_INCLUDE := /usr/include/python3.5m \ 82 | # /usr/lib/python3.5/dist-packages/numpy/core/include 83 | 84 | # We need to be able to find libpythonX.X.so or .dylib. 85 | PYTHON_LIB := /usr/lib 86 | # PYTHON_LIB := $(ANACONDA_HOME)/lib 87 | 88 | # Homebrew installs numpy in a non standard path (keg only) 89 | # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include 90 | # PYTHON_LIB += $(shell brew --prefix numpy)/lib 91 | 92 | # Uncomment to support layers written in Python (will link against Python libs) 93 | WITH_PYTHON_LAYER := 1 94 | 95 | # Whatever else you find you need goes here. 96 | INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial 97 | LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial 98 | 99 | # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies 100 | # INCLUDE_DIRS += $(shell brew --prefix)/include 101 | # LIBRARY_DIRS += $(shell brew --prefix)/lib 102 | 103 | # NCCL acceleration switch (uncomment to build with NCCL) 104 | # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0) 105 | USE_NCCL := 1 106 | 107 | # Uncomment to use `pkg-config` to specify OpenCV library paths. 108 | # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.) 109 | # USE_PKG_CONFIG := 1 110 | 111 | # N.B. both build and distribute dirs are cleared on `make clean` 112 | BUILD_DIR := build 113 | DISTRIBUTE_DIR := distribute 114 | 115 | # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 116 | # DEBUG := 1 117 | 118 | # The ID of the GPU that 'make runtest' will use to run unit tests. 119 | TEST_GPUID := 3 120 | 121 | # enable pretty build (comment to see full commands) 122 | Q ?= @ 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Easy-LAB 2 | 3 | Look at Boundary: A Boundary-Aware Face Alignment Algorithm 4 | 5 | # Installing 6 | 7 | 1.Download the **repo** below, as well as pretrained models 8 | 9 | 2.Replace **Makefile.config** 10 | 11 | 3.make all -j8 12 | 13 | 4.run **compile.sh** 14 | 15 | # Reference 16 | 17 | https://github.com/wywu/LAB 18 | -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export LD_LIBRARY_PATH=/home/hans/LAB-master/build/lib/:$LD_LIBRARY_PATH 3 | g++ -I/home/hans/LAB-master/include -I/home/hans/LAB-master/build/src -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -O3 -D CPU_ONLY -MMD -MP -MF"LAB.d" -MT"LAB.o" -o "LAB.o" "./LAB.cpp" 4 | g++ -L/home/hans/LAB-master/build/lib -o "caffe_LAB" ./LAB.o -lcaffe -lglog -lopencv_core -lopencv_contrib -lprotobuf -lboost_system -lopencv_imgproc -lopencv_highgui 5 | --------------------------------------------------------------------------------