Giter Club home page Giter Club logo

face-alignment-at-3000fps's Introduction

face-alignment-at-3000fps

C++ implementation of Face Alignment at 3000 FPS via Regressing Local Binary Features.

Prepare Data

We can download dataset from here. The dataset contains 68 points for every face, however it doesn't provide a bounding box for faces. We need our face detector to generate face bounding box (I think it is resonable because we should ues the same face detector for training and prediction).

Download the dataset and extract the data (xxx.jpg and xxx.pts) to the directory data, e.g. data/68. We also need two text file data/68/Path_Images_train.txt and data/68/Path_Images_test.txt to list the images used for train and test. The path can be relative like ../data/68/xxx.jpg or absolute like /home/zhangjie/projects/face-alignment-at-3000fps/data/68/xxx.jpg or E:/projects/face-alignment-at-3000fps/data/68/xxx.jpg.

Build the project

We only need OpenCV and CMake to build the project.

$ git clone https://github.com/luoyetx/face-alignment-at-3000fps.git
$ cd face-alignment-at-3000fps
$ mkdir build && cd build
$ cmake ..

If you are on Linux, simply use make to compile the project. If you are on Windows, you may compile using Visual Studio.

Train

Since we have prepare the data, $ ./FaceAlignment prepare will generate two text file train.txt and test.txt under ../data/68. These text files are used for training and testing, each line points out an image path and face bounding box in this image with facial points location. We use VJ detector provided by OpenCV, you can use your own face detector to generate these two text file.

$ ./FaceAlignment train will start training and result will be lied in the directory model. $ ./FaceAlignment test will test the model on test data. If you have a Desktop Environment on the Linux, $ ./FaceAlignment run will do the prediction over test data by presenting a window to show the result.

Tuning

The Configure is under src/lbf/common.cpp/Config::Config, modify the config under your own condition.

Notice

The relative path used in source code are all start from ../build, you may change this under your own condition.

Pre-trained Model

I will not provide a pre-trained model, please train the code on your own data.

Some Test

License

BSD 3-Clause

Reference

face-alignment-at-3000fps's People

Contributors

luoyetx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

face-alignment-at-3000fps's Issues

代码速度问题

我把3000fps运行程序在i5的电脑上运行速度是4ms左右,然而将代码移植到arm-v7 的开发板上运行,运行速度是90ms 左右,正常情况下,电脑和板子的速度比是1:6;请问是什么原因呢?

dataset挂了

luoyetx:

你的dataset挂了,能不能提供一个有效的dataset地址?

Assertion fail on FaceAlignment prepare

line 49 from prepare.cpp: assert(inFile && outFile);

./FaceAlignment prepare
FaceAlignment: /home/bh/git/alignment/face1/src/prepare.cpp:49: void genTxt(const string&, const string&): Assertion `inFile && outFile' failed.
[1]    8831 abort (core dumped)  ./FaceAlignment prepare

怎样写数据库?

数据库是不是只要往Path_Images_train.txt和Path_Images_test.txt中写好.jpg和.pts的路径就好了?训练集大概需要多少张图片呢

test的时候用到了ground true数据

for (int i = 0; i < N; i++) {
fscanf(fd, "%s", img_path);
for (int j = 0; j < 4; j++) {
fscanf(fd, "%lf", &bbox[j]);
}
for (int j = 0; j < landmark_n; j++) {
fscanf(fd, "%lf%lf", &x[j], &y[j]);
}
Mat img = imread(img_path);
// crop img
double x_min, y_min, x_max, y_max;
x_min = *min_element(x.begin(), x.end());
x_max = *max_element(x.begin(), x.end());
y_min = *min_element(y.begin(), y.end());
y_max = *max_element(y.begin(), y.end());
x_min = max(0., x_min - bbox[2] / 2);
x_max = min(img.cols - 1., x_max + bbox[2] / 2);
y_min = max(0., y_min - bbox[3] / 2);
y_max = min(img.rows - 1., y_max + bbox[3] / 2);
double x_, y_, w_, h_;
x_ = x_min; y_ = y_min;
w_ = x_max - x_min; h_ = y_max - y_min;
BBox bbox_(bbox[0] - x_, bbox[1] - y_, bbox[2], bbox[3]);
Rect roi(x_, y_, w_, h_);
img = img(roi).clone();

    Mat gray;
    cvtColor(img, gray, CV_BGR2GRAY);
    LOG("Run %s", img_path);
    Mat shape = lbf_cascador.Predict(gray, bbox_);
    img = drawShapeInImage(img, shape, bbox_);
    imshow("landmark", img);
    waitKey(0);
}

test的时候用到了ground truth的数据,是不是在做另外其他图像没有.pts文件就不能检测了?

memory free ERROR @x64 train

Dear luoyetx,
The code on your github could do memory Error when runing 'train' on building under X64 mode.

lbp.cpp
#define FREE_MODEL(model)

That wasn't happend on running under X86 mode.

Did that happened before?
@luoyetx

Regards!

Rui

why current_shapes[idx] = bboxes_[i].ReProject(bboxes_[k].Project(gt_shapes_[k])) ?

Dear luoyetx,
i am reading your code, and i find that in the trian.cpp, line 180, i can not understand why we do like this? one face's initial shape is initialize by another face?

int N = imgs_.size();
int L = N*config.initShape_n;
vector<Mat> imgs(L), gt_shapes(L), current_shapes(L);
vector<BBox> bboxes(L);
RNG rng(getTickCount());
for (int i = 0; i < N; i++) {
    for (int j = 0; j < config.initShape_n; j++) {
        int idx = i*config.initShape_n + j;
        int k = 0;
        do {
            //if (i < (N / 2)) k = rng.uniform(0, N / 2);
            //else k = rng.uniform(N / 2, N);
            k = rng.uniform(0, N);
        } while (k == i);
        imgs[idx] = imgs_[i];                               
        gt_shapes[idx] = gt_shapes_[i];
        bboxes[idx] = bboxes_[i];
        current_shapes[idx] = bboxes_[i].ReProject(bboxes_[k].Project(gt_shapes_[k])); <----line 180
    }
}

SWAP of landmarks

Hi

I see in the data_augmentation function of train.cpp, there is macro SWAP. I am worried that it destroys the data integrity. May I know why this is being done ?

Thank you

out of Memory

Hi, i successed in training the model using 300w which contain about 4k images.

but when i do data-argument(including rotation and offset faceRect),the images from 4K to 100k.

and when training again,it occur a error ,i find in function parseTxt(), the cpu available from 28G to 1G

after loading about 18k images.

how can i solve the problem about cpu memory.

Thanks

webcam model test?

I've tried jwyang's implementation of the algorithm. The result is quite poor. I tired it on webcam, and the points detected are always shaking. and the side face detection is also unacceptable. So what is the differences between your code and jwyang's. Any improvement on that?

alignment model

Hi
thank you for your sharing code. can you provide a pre-train model?

thanks

variance question

I understood this code.
'double m1 = cv::mean(vec_)[0];'
'double m2 = cv::mean(vec_.mul(vec_))[0];'
'double variance = m2 - m1*m1;'

But I don't understand formula below.
'double variance_all = (calcVariance(delta_shapes.col(0)) + calcVariance(delta_shapes.col(1)))*N;'

Does 2-D variance addition each 1-dimensional variance?
What means of N?
N is count of training sample. But I don't understand why multiply N.

Could you please provide some reference material?

Lib versions problem

$ ./FaceAlignment prepare    
$ ./FaceAlignment: /home/bh/anaconda3/lib/libgomp.so.1: version `GOMP_4.0' not found (required by ./FaceAlignment)
$ ./FaceAlignment: /home/bh/anaconda3/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./FaceAlignment)

Trying to use ./FaceAlignment prepare causes this error, related to wrong library versions.
Any tip to solve this?

SimilarityTransform returning identity

Hi,

I see that the calcSimilarityTransform() function always returns identity matrix for rotation and only the scale is computed which is also close to 1 in almost all the cases. Is this a bug in the function or is it how it should be ? (Mean face landmarks are always vertical because of the flipped shapes.)

Because, if you use lfpw/afw/helen datasets, there are many cases where the face is not vertical but tilted up to some degrees. It returns identity rotation in these cases as well.

Could you help me with this problem ?
Thanks

Dataset site is offline

The dataset required by this algorithm is offline.
Another mirror is required.
I suggest putting it on the repo.

Assertion error on void genTxt()

When I try to ./FaceAlignment prepare:

FaceAlignment: /home/bh/git/face-alignment-at-3000fps/src/prepare.cpp:49: void genTxt(const string&, const string&): Assertion `inFile && outFile' failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.