https://github.com/mnjm/facial-landmarks-cnn
Facial Landmark Detection using CNN with Face Pose Estimation
https://github.com/mnjm/facial-landmarks-cnn
face-alignment facial-landmarks
Last synced: about 2 months ago
JSON representation
Facial Landmark Detection using CNN with Face Pose Estimation
- Host: GitHub
- URL: https://github.com/mnjm/facial-landmarks-cnn
- Owner: mnjm
- License: gpl-3.0
- Created: 2024-06-04T17:47:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-01T09:11:05.000Z (about 1 year ago)
- Last Synced: 2025-05-31T13:05:25.084Z (5 months ago)
- Topics: face-alignment, facial-landmarks
- Language: Python
- Homepage:
- Size: 22.7 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Facial Landmark Detection using CNN
Here is a quick demo
**8 Points with Face alignment / Head Pose**

**6 Points**

**Prerequisites**



## Datasets
| Sources |
| -------- |
| [300-VW](https://ibug.doc.ic.ac.uk/resources/300-VW/) |
| [300-W](https://ibug.doc.ic.ac.uk/resources/300-W/) |
| [AFW](https://www.ics.uci.edu/~xzhu/face/) |
| [HELEN](http://www.ifp.illinois.edu/~vuongle2/helen/) |
| [IBUG](https://ibug.doc.ic.ac.uk/resources/facial-point-annotations/) |
| [LFPW](https://neerajkumar.org/databases/lfpw/) |
- *Some* datasets mentioned above came pre-split into training and test sets. Others I manually split them randomly.
- Prepared dataset is stored and served to the model as tfrecord files in sharded fashion
### Datasets file structure
```
{ dataset }
├── testset
│ ├── {img}.(jpg|png)
│ ├── {img}.pts
└── trainset
├── {img}.(jpg|png)
├── {img}.pts
```
**[300-VW](https://ibug.doc.ic.ac.uk/resources/300-VW/)**
Since this dataset is composed of (.avi) video files (unlike the others), It should be served in this format.
```
300VW
├── testset
│ ├── {sample name}
│ │ ├── annot / {frame_no}.pts
│ │ └── vid.avi
└── trainset
├── {sample name}
│ ├── annot / {frame_no}.pts
│ └── vid.avi
frame_no format "%06d"
```
Note: Dataset base dir name `300VW`, this is hardcoded in `prep_tfrecords.py`.
## Generate TFRecord files
Provide the dataset directory and the path to store the TFRecord files
```bash
python prep_tfrecords.py (--test_set) --n_points <6 (or) 8>
```
## Training
Command to train the model.
```bash
python train.py \
--n_points <6 (or) 8> \
--tfrecords_dir \
--load_from \ # This can be skipped
--epochs 10 --batch_size 1024 --learning_rate 0.001
```
- Check [here](https://github.com/mnjm/facial-landmarks-cnn/blob/main/train.py#L10C1-L10C57) for model types
## Evaluate
```bash
python train.py \
--n_points <6 (or) 8> \
--tfrecords_dir \
--load_from \
--eval_model
```
## Export
Best model can be exported to Keras native `.keras` format
```bash
python train.py \
--load_from \
--export_model
```
## Visual Test
To visually test the model on a video file or directory containing images, run the below command
```
python visual_test.py (--save_video) --n_points <6 (or) 8>
```
*`--save_video` will save the visual output to `output.mp4`*
### Visual Test with Face alignment / Head Pose
**Only works on 8pts**
To visually test the model on a video file or directory containing images, run the below command
```
python visual_test.py (--save_video) --n_points 8 --draw_headpose
```
## Addendum
- Model provided [here](https://github.com/mnjm/facial-landmarks-cnn/blob/main/models/from_github.py) is from [ccn-facial-landmark](https://github.com/yinguobing/cnn-facial-landmark).
## License
