Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ff62bf8

Browse files
author
D-X-Y
committed
Initial Commit
0 parents  commit ff62bf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4877
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
__pycache__
2+
*/__pycache__
3+
*/*/__pycache__
4+
snapshots
5+
cache_data/cache
6+
cache_data/lists
7+
.DS_Store
8+
*/.DS_Store
9+
*/*/.DS_Store
10+
*.swp
11+
*/*.swp
12+
*/*/*.swp
13+
*/AFLWinfo_release.mat
14+
AFLWinfo_release.mat

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Code of Conduct
2+
3+
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the [full text](https://code.facebook.com/pages/876921332402685/open-source-code-of-conduct) so that you can understand what actions will and will not be tolerated.

CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Contributing to Supervision-by-Registration (SBR)
2+
We want to make contributions to this project as easy and transparent as possible.
3+
4+
## Our Development Process
5+
Preliminary Implementations.
6+
7+
## Pull Requests
8+
We actively welcome your pull requests.
9+
10+
1. Fork the repo and create your branch from `master`.
11+
2. If you've added code that should be tested, add tests.
12+
3. If you've changed APIs, update the documentation.
13+
4. Ensure the test suite passes.
14+
5. Make sure your code lints.
15+
6. If you haven't already, complete the Contributor License Agreement ("CLA").
16+
17+
## Contributor License Agreement ("CLA")
18+
In order to accept your pull request, we need you to submit a CLA. You only need
19+
to do this once to work on any of Facebook's open source projects.
20+
21+
Complete your CLA here: <https://code.facebook.com/cla>
22+
23+
## Issues
24+
We use GitHub issues to track public bugs. Please ensure your description is
25+
clear and has sufficient instructions to be able to reproduce the issue.
26+
27+
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
28+
disclosure of security bugs. In those cases, please go through the process
29+
outlined on that page and do not file a public issue.
30+
31+
## Coding Style
32+
* 2 spaces for indentation rather than tabs
33+
* ...
34+
35+
## License
36+
By contributing to SBR, you agree that your contributions will be licensed
37+
under the LICENSE file in the root directory of this source tree.

LICENSE

Lines changed: 399 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Supervision-by-Registration: An Unsupervised Approach to Improve the Precision of Facial Landmark Detectors
2+
By Xuanyi Dong, Shoou-I Yu, Xinshuo Weng, Shih-En Wei, Yi Yang, Yaser Sheikh
3+
4+
University of Technology Sydney, Facebook Reality Labs
5+
6+
## Introduction
7+
We propose a method to find facial landmarks (e.g. corner of eyes, corner of mouth, tip of nose, etc) more precisely.
8+
Our method utilizes the fact that objects move smoothly in a video sequence (i.e. optical flow registration) to improve an existing facial landmark detector.
9+
The key novelty is that no additional human annotations are necessary to improve the detector, hence it is an “unsupervised approach”.
10+
11+
![demo](https://github.com/facebookresearch/supervision-by-registration/blob/master/cache_data/cache/demo.gif)
12+
13+
## Citation
14+
If you find that Supervision-by-Registration helps your research, please cite the paper:
15+
```
16+
@inproceedings{dong2018sbr,
17+
title={{Supervision-by-Registration}: An Unsupervised Approach to Improve the Precision of Facial Landmark Detectors},
18+
author={Dong, Xuanyi and Yu, Shoou-I and Weng, Xinshuo and Wei, Shih-En and Yang, Yi and Sheikh, Yaser},
19+
booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
20+
pages={360--368},
21+
year={2018}
22+
}
23+
```
24+
25+
## Requirements
26+
- PyTorch >= 0.4.0
27+
- Python3.6
28+
29+
## Data Preparation
30+
31+
See the README in `cache_data`.
32+
33+
### Dataset Format
34+
Each dataset is saved as one file, in which each row indicates one specific face in one image or one video frame.
35+
The format of one line :
36+
```
37+
image_path annotation_path x1 y1 x2 y2 (face_size)
38+
```
39+
- *image_path*: the image (video frame) file path of that face.
40+
- *annotation_path*: the annotation file path of that face (annotation is the coordinates of all landmarks)
41+
- *x1, y1, x2, y2*: the coordinates of left-upper and right-lower points of the face bounding box.
42+
- *face_size*: an optional item. If set this value, we use the `face_size` to compute the NME; otherwise, we use the distance between two pre-defined points to compute the NME.
43+
44+
## Training
45+
46+
See the `configs` directory for some example configurations.
47+
### Basic Training
48+
```
49+
python ./exps/basic_main.py [<required arguments>]
50+
```
51+
The argument list is loaded by `./lib/config_utils/basic_args.py`.
52+
An examples script can is `./scripts/300W-DET.sh`, and you can simple run to train the base detector on the `300-W` dataset.
53+
```
54+
sh scripts/300W-DET.sh
55+
```
56+
57+
### Improving the Detector by SBR
58+
```
59+
python ./exps/lk_main.py [<required arguments>]
60+
```
61+
The argument list is loaded by `./lib/config_utils/lk_args.py`.
62+
63+
64+
#### An example to train SBR on the unlabeled sequences
65+
The `init_model` parameter is the path to the detector trained in the `Basic Training` section.
66+
```
67+
sh scripts/demo_sbr.sh
68+
```
69+
To see visualization results use the commands in `Visualization`.
70+
71+
#### An example to train SBR on your own data
72+
See the script `./scripts/sbr_example.sh`, and some parameters should be replaced by your own data.
73+
74+
75+
## Evaluation
76+
77+
When using the `basic_main.py` or `lk_main.py`, we evaluate the testing datasets automatically.
78+
79+
To evaluate a single image, you can use the following script to compute the coordinates of 68 facial landmarks of the target image:
80+
```
81+
python ./exps/eval.py --image ./cache_data/cache/self.jpeg --model ./snapshots/300W-CPM-DET/checkpoint/cpm_vgg16-epoch-049-050.pth --face 250 150 900 1100 --save ./cache_data/cache/test.jpeg
82+
```
83+
- image : the input image path
84+
- model : the snapshot path
85+
- face : the face bounding box
86+
- save : save the visualized results
87+
88+
89+
## Visualization
90+
91+
After training the SBR on the demo video or models on other datasets, you can use the `./exps/vis.py` code to generate the visualization results.
92+
```
93+
python ./exps/vis.py --meta snapshots/CPM-SBR/metas/eval-start-eval-00-01.pth --save cache_data/cache/demo-detsbr-vis
94+
ffmpeg -start_number 3 -i cache_data/cache/demo-detsbr-vis/image%04d.png -b:v 30000k -vf "fps=30" -pix_fmt yuv420p cache_data/cache/demo-detsbr-vis.mp4
95+
96+
python ./exps/vis.py --meta snapshots/CPM-SBR/metas/eval-epoch-049-050-00-01.pth --save cache_data/cache/demo-sbr-vis
97+
ffmpeg -start_number 3 -i cache_data/cache/demo-sbr-vis/image%04d.png -b:v 30000k -vf "fps=30" -pix_fmt yuv420p cache_data/cache/demo-sbr-vis.mp4
98+
```
99+
- meta : the saved prediction files
100+
- save : the directory path to save the visualization results
101+
102+
103+
## License
104+
supervision-by-registration is released under the [CC-BY-NC license](https://github.com/facebookresearch/supervision-by-registration/blob/master/LICENSE).
105+
106+
107+
## Useful information
108+
109+
### 1. train on your own video data
110+
You should look at the `./lib/datasets/VideoDataset.py` and `./lib/datasets/parse_utils.py`, and add how to find the neighbour frames when giving one image path.
111+
For more details, see the `parse_basic` function in `lib/datasets/parse_utils.py`.
112+
113+
### 2. warnings when training the AFLW datase
114+
It is ok to show the following warnings. Since some images in the AFLW dataset are in the wrong format, PIL will raise some warnings when loading these images. These warnings do not affect the training performance.
115+
```
116+
TiffImagePlugin.py:756: UserWarning: Corrupt EXIF data. Expecting to read 12 bytes but only got 6.
117+
```
118+
119+
### Contact
120+
To ask questions or report issues, please open an issue on [the issues tracker](https://github.com/facebookresearch/supervision-by-registration/issues).

cache_data/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.lst
2+
temp
3+
EX300.sh

cache_data/README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Dataset Preparation
2+
The raw dataset should be put into the `$HOME/datasets/landmark-datasets`. The layout should be organized as the following screen shot.
3+
4+
![layout](https://github.com/facebookresearch/supervision-by-registration/blob/master/cache_data/cache/dir-layout.png)
5+
6+
## [300-W](https://ibug.doc.ic.ac.uk/resources/300-W/)
7+
8+
### Download
9+
- 300-W consits of several different datasets
10+
- Create directory to save images and annotations: mkdir ~/datasets/landmark-datasets/300W
11+
- To download i-bug: https://ibug.doc.ic.ac.uk/download/annotations/ibug.zip
12+
- To download afw: https://ibug.doc.ic.ac.uk/download/annotations/afw.zip
13+
- To download helen: https://ibug.doc.ic.ac.uk/download/annotations/helen.zip
14+
- To download lfpw: https://ibug.doc.ic.ac.uk/download/annotations/lfpw.zip
15+
- To download the bounding box annotations: https://ibug.doc.ic.ac.uk/media/uploads/competitions/bounding_boxes.zip
16+
- In the folder of `~/datasets/landmark-datasets/300W`, there are four zip files ibug.zip, afw.zip, helen.zip, and lfpw.zip
17+
```
18+
unzip ibug.zip -d ibug
19+
mv ibug/image_092\ _01.jpg ibug/image_092_01.jpg
20+
mv ibug/image_092\ _01.pts ibug/image_092_01.pts
21+
22+
unzip afw.zip -d afw
23+
unzip helen.zip -d helen
24+
unzip lfpw.zip -d lfpw
25+
unzip bounding_boxes.zip ; mv Bounding\ Boxes Bounding_Boxes
26+
```
27+
The 300W directory is in `$HOME/datasets/landmark-datasets/300W` and the sturecture is:
28+
```
29+
-- afw
30+
-- Bounding_boxes
31+
-- helen
32+
-- ibug
33+
-- lfpw
34+
```
35+
36+
Then you use the script to generate the 300-W list files.
37+
```
38+
python generate_300W.py
39+
```
40+
All list files will be saved into `./lists/300W/`. The files `*.DET` use the face detecter results for face bounding box. `*.GTB` use the ground-truth results for face bounding box.
41+
42+
#### can not find the `*.mat` files for 300-W.
43+
The download link is in the official [300-W website](https://ibug.doc.ic.ac.uk/resources/300-W).
44+
```
45+
https://ibug.doc.ic.ac.uk/media/uploads/competitions/bounding_boxes.zip
46+
```
47+
The zip file should be unzipped, and all extracted mat files should be put into `$HOME/datasets/landmark-datasets/300W/Bounding_Boxes`.
48+
49+
## [AFLW](https://www.tugraz.at/institute/icg/research/team-bischof/lrs/downloads/aflw/)
50+
51+
Download the aflw.tar.gz file in `$HOME/datasets/landmark-datasets` and extract it by `tar xzvf aflw.tar.gz`.
52+
```
53+
mkdir $HOME/datasets/landmark-datasets/AFLW
54+
cp -r aflw/data/flickr $HOME/datasets/landmark-datasets/AFLW/images
55+
```
56+
57+
The structure of AFLW is:
58+
```
59+
--images
60+
--0
61+
--2
62+
--3
63+
```
64+
65+
Download the [AFLWinfo_release.mat](http://mmlab.ie.cuhk.edu.hk/projects/compositional/AFLWinfo_release.mat) from [this website](http://mmlab.ie.cuhk.edu.hk/projects/compositional.html) into `./cache_data`. This is the revised annotation of the full AFLW dataset.
66+
67+
Generate the AFLW dataset list file into `./lists/AFLW`.
68+
```
69+
python aflw_from_mat.py
70+
```
71+
72+
## [300VW](https://ibug.doc.ic.ac.uk/resources/300-VW/)
73+
Download `300VW_Dataset_2015_12_14.zip` into `$HOME/datasets/landmark-datasets` and unzip it into `$HOME/datasets/landmark-datasets/300VW_Dataset_2015_12_14`.
74+
75+
Use the following command to extract the raw video into the image format.
76+
```
77+
python extrct_300VW.py
78+
sh ./cache/Extract300VW.sh
79+
```
80+
81+
Generate the 300-VW dataset list file.
82+
```
83+
python generate_300VW.py
84+
```
85+
86+
## a short demo video sequence
87+
88+
The raw video is `./cache_data/cache/demo-sbr.mp4`.
89+
- use `ffmpeg -i ./cache/demo-sbr.mp4 ./cache/demo-sbrs/image%04d.png` to extract the frames into `/cache/demo-sbrs/`
90+
Then use `python demo_list.py` to generate the list file for the demo video.
91+
92+
# Citation
93+
If you use the 300-W dataset, please cite the following papers.
94+
```
95+
@article{sagonas2016300,
96+
title={300 faces in-the-wild challenge: Database and results},
97+
author={Sagonas, Christos and Antonakos, Epameinondas and Tzimiropoulos, Georgios and Zafeiriou, Stefanos and Pantic, Maja},
98+
journal={Image and Vision Computing},
99+
volume={47},
100+
pages={3--18},
101+
year={2016},
102+
publisher={Elsevier}
103+
}
104+
@inproceedings{sagonas2013300,
105+
title={300 faces in-the-wild challenge: The first facial landmark localization challenge},
106+
author={Sagonas, Christos and Tzimiropoulos, Georgios and Zafeiriou, Stefanos and Pantic, Maja},
107+
booktitle={Proceedings of the IEEE International Conference on Computer Vision Workshops},
108+
pages={397--403},
109+
year={2013},
110+
organization={IEEE}
111+
}
112+
```
113+
If you use the 300-VW dataset, please cite the following papers.
114+
```
115+
@inproceedings{chrysos2015offline,
116+
title={Offline deformable face tracking in arbitrary videos},
117+
author={Chrysos, Grigoris G and Antonakos, Epameinondas and Zafeiriou, Stefanos and Snape, Patrick},
118+
booktitle={Proceedings of the IEEE International Conference on Computer Vision Workshops},
119+
pages={1--9},
120+
year={2015}
121+
}
122+
@inproceedings{shen2015first,
123+
title={The first facial landmark tracking in-the-wild challenge: Benchmark and results},
124+
author={Shen, Jie and Zafeiriou, Stefanos and Chrysos, Grigoris G and Kossaifi, Jean and Tzimiropoulos, Georgios and Pantic, Maja},
125+
booktitle={Proceedings of the IEEE International Conference on Computer Vision Workshops},
126+
pages={50--58},
127+
year={2015}
128+
}
129+
@inproceedings{tzimiropoulos2015project,
130+
title={Project-out cascaded regression with an application to face alignment},
131+
author={Tzimiropoulos, Georgios},
132+
booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
133+
pages={3659--3667},
134+
year={2015}
135+
}
136+
```
137+
If you use the AFLW dataset, please cite the following papers.
138+
```
139+
@inproceedings{koestinger2011annotated,
140+
title={Annotated facial landmarks in the wild: A large-scale, real-world database for facial landmark localization},
141+
author={Koestinger, Martin and Wohlhart, Paul and Roth, Peter M and Bischof, Horst},
142+
booktitle={IEEE International Conference on Computer Vision Workshops},
143+
pages={2144--2151},
144+
year={2011},
145+
organization={IEEE}
146+
}
147+
```

0 commit comments

Comments
 (0)