Implementation of DNN face landmark detector from python by https://github.com/1adrianb/face-alignment
Please Refer to here for more details.
Prerequisite
- Visual studio 2015/17
- Libtorch 1.0.0
- dlib 19.16
- Opencv 2/3 --
./face-alignment/ folder contains the base python for the DNN implementation
./cpp_app/ folder contains example of loading the torch script in C++
-
To convert the pytorch network model for C++ use, the model must be traced. There is two ways to convert the model into torch script.
-
Tracing
- Fast, may not be able to handle complex control flow
-
Annotation
- Slow (can be very slow), able to handle complex control flow Please refer to Pytorch C++ documentation for more detail explanation
-
Serialize the model with it's weight
- Save the model in file
-
Load it in C++ application
- For the landmark detector, some pre-processing is done using dlib and pytorch.
- In the C++ implementation, these are re-implemented using dlib for C++ and libtorch. (The result might not be 100% same with the python version)
Using prebuild library for vs2015/17 x64 release only. Please build from source for different build. Include Directories
- $(ProjectDir)include\dlib
- $(ProjectDir)include\libtorch
- $(ProjectDir)include\libtorch\torch\csrc\api\include
- $(ProjectDir)include\opencv
Library Directories
- $(ProjectDir)lib\dlib
- $(ProjectDir)lib\libtorch
- $(ProjectDir)lib\opencv
Linker Input
- Add to vs project 'linker->input->additional dependencies'
- Copy the following
dlib19.16.0_release_64bit_msvc1900.lib
torch.lib
caffe2.lib
libprotobuf.lib
c10.lib
From vs solution explorer->properties->add existing item Add '/include/dlib/dlib/all/source.cpp'
Copy dll from x64->Release
torch.dll
caffe2.dll
libiomp5md.dll
c10.dll
(opencv).dll