Skip to content

jzi040941/face-alignment-CPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

face_alignment_cpp

2D and 3D Face alignment library build using pytorch https://www.adrianbulat.com c++ implementation

Contents

  1. Requirements
  2. Build
  3. Usage

Requirements

  • Pytorch (tag: pytorch v1.4)
  • Libtorch
  • OpenCV

Build

Step 1

Export your pytorch model to torch script file, We will simply use resnet50 in this demo

Step 2

Write your C++ program, check the file prediction.cpp for more detial.

PS: module->to(at::kCUDA) and input_tensor.to(at::kCUDA) will switch your model & tensor to GPU mode,
comment out them if you just want to use CPU mode.

Step 3

Write a CMakeLists.txt, the version of OpenCV must the same as your libtorch. Otherwise, you may get the compile error:

error: undefined reference to `cv::imread(std::string const&, int)'

check issues 14684 and issues 14620 for more details.

Usage

  • run model_trace.py, then you will get a file resnet50.pt
  • compile your cpp program, you need to use -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch, for example:
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/home/cgilab/pytorch/torch/lib/tmp_install ..
make
  • test your program

classifier <path-to-exported-script-module> <path-to-lable-file>


About

2D and 3D Face alignment library build using pytorch https://www.adrianbulat.com c++ implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published