Joint-Face-Detection-and-Alignment
Caffe and Python implementation of Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks.
Set up
Set up environment and copy C++ layer code to Caffe's source code tree.
$ export PYTHONPATH=/path/to/Joint-Face-Detection-and-Alignment:$PYTHONPATH
$ export CAFFE_HOME=/path/to/caffe
$ sh layers/copy.sh
Compile Caffe following its document.
Prepare data
Download dataset WIDER, CelebA and FDDB. Put them in data directory like below.
data
โโโ CelebA
โย ย โโโ img_celeba
โโโ fddb
โ โโโ FDDB-folds
โ โโโ images
โ โย ย โโโ 2002
โ โย ย โโโ 2003
โ โโโ result
โ โโโ images
โโโ WIDER
โโโ wider_face_split
โโโ WIDER_test
โโโ WIDER_train
โโโ WIDER_val
I have write a matlab script to extract WIDER FACE info from matlab mat
file to txt
file.
Train
Prepare data and train network follow the commands in train.sh
.
Test
Test the model with demo.py
for simple detection and fddb.py
for FDDB benchmark.
Memory Issue
Since pNet
may output many bboxes for rNet
and Caffe's Blob
never realloc the memory if your new data is smaller, this makes Blob
only grow the memory and never reduce, which looks like a memory leak. It is fine for most cases but not for our case. You may modify src/caffe/blob.cpp
if you encounter the memory issue.
template <typename Dtype>
void Blob<Dtype>::Reshape(const vector<int>& shape) {
/* some code */
if (count_ > capacity_) { // never reduce the memory here
capacity_ = count_;
data_.reset(new SyncedMemory(capacity_ * sizeof(Dtype)));
diff_.reset(new SyncedMemory(capacity_ * sizeof(Dtype)));
}
}
template <typename Dtype>
void Blob<Dtype>::Reshape(const vector<int>& shape) {
/* some code */
if (count_ != capacity_) { // make a new data buffer
capacity_ = count_;
data_.reset(new SyncedMemory(capacity_ * sizeof(Dtype)));
diff_.reset(new SyncedMemory(capacity_ * sizeof(Dtype)));
}
}