This is a Gluon implementation of LipNet: End-to-End Sentence-level Lipreading
- Python 3.6.4
- MXNet 1.3.0
- Required disk space: 35 GB
pip install -r requirements.txt
- The GRID audiovisual sentence corpus (http://spandh.dcs.shef.ac.uk/gridcorpus/)
- GRID is a large multi-talker audiovisual sentence corpus to support joint computational-behavioral studies in speech perception. In brief, the corpus consists of high-quality audio and video (facial) recordings of 1000 sentences spoken by each of 34 talkers (18 male, 16 female). Sentences are of the form "put red at G9 now". The corpus, together with transcriptions, is freely available for research use.
- Video: (normal)(480 M each)
- Each movie has one sentence consist of 6 words.
- Align: word alignments (190 K each)
- One align has 6 words. Each word has start time and end time. But this tutorial needs just sentence because of using ctc-loss.
You can train the model yourself in the following sections, you can test a pretrained model's inference, or resume training from the model checkpoint. To work with the provided pretrained model, first download it, then run one of the provided Python scripts for inference (infer.py) or training (main.py).
- Download the pretrained model
- Try inference with the following:
python infer.py model_path='checkpoint/epoches_81_loss_15.7157'
- Resume training with the following:
python main.py model_path='checkpoint/epoches_81_loss_15.7157'
You can prepare the data yourself, or you can download preprocessed data.
There are two download routes provided for the preprocessed data.
To download tar zipped files by link, download the following files and extract in a folder called data
in the root of this example folder. You should have the following structure:
/lipnet/data/align
/lipnet/data/datasets
To get the folders and files all unzipped with AWS CLI, can use the following command. This will provide the folder structure for you. Run this command from /lipnet/
:
aws s3 sync s3://mxnet-public/lipnet/data .
- Outputs
- The Total Movies(mp4): 16GB
- The Total Aligns(text): 134MB
- Arguments
- src_path : Path for videos (default='./data/mp4s/')
- align_path : Path for aligns (default='./data/')
- n_process : num of process (default=1)
cd ./utils && python download_data.py --n_process=$(nproc)
- Using Face Landmark Detection(http://dlib.net/)
- If there is no landmark, it download automatically.
- Using Face Landmark Detection, It extract the mouth from a video.
-
example:
-
video: ./data/mp4s/s2/bbbf7p.mpg
-
align(target): ./data/align/s2/bbbf7p.align : 'sil bin blue by f seven please sil'
-
Video to the images (75 Frames)
Frame 0 | Frame 1 | ... | Frame 74 |
---|---|---|---|
... |
- Extract the mouth from images
Frame 0 | Frame 1 | ... | Frame 74 |
---|---|---|---|
... |
- Save the result images into tgt_path.
-
Arguments
- src_path : Path for videos (default='./data/mp4s/')
- tgt_path : Path for preprocessed images (default='./data/datasets/')
- n_process : num of process (default=1)
-
Outputs
- The Total Images(png): 19GB
-
Elapsed time
- About 54 Hours using 1 process
- If you use the multi-processes, you can finish the number of processes faster.
- e.g) 9 hours using 6 processes
You can run the preprocessing with just one processor, but this will take a long time (>48 hours). To use all of the available processors, use the following command:
cd ./utils && python preprocess_data.py --n_process=$(nproc)
The training data folder should look like :
<train_data_root>
|--datasets
|--s1
|--bbir7s
|--mouth_000.png
|--mouth_001.png
...
|--bgaa8p
|--mouth_000.png
|--mouth_001.png
...
|--s2
...
|--align
|--bw1d8a.align
|--bggzzs.align
...
After you have acquired the preprocessed data you are ready to train the lipnet model.
-
According to LipNet: End-to-End Sentence-level Lipreading, four (S1, S2, S20, S22) of the 34 subjects are used for evaluation. The other subjects are used for training.
-
To use the multi-gpu, it is recommended to make the batch size $(num_gpus) times larger.
- e.g) 1-gpu and 128 batch_size > 2-gpus 256 batch_size
-
arguments
- batch_size : Define batch size (default=64)
- epochs : Define total epochs (default=100)
- image_path : Path for lip image files (default='./data/datasets/')
- align_path : Path for align files (default='./data/align/')
- dr_rate : Dropout rate(default=0.5)
- num_gpus : Num of gpus (if num_gpus is 0, then use cpu) (default=1)
- num_workers : Num of workers when generating data (default=0)
- model_path : Path of pretrained model (default=None)
python main.py
-
72 CPU cores
-
1 GPU (NVIDIA Tesla V100 SXM2 32 GB)
-
128 Batch Size
- It takes over 24 hours (60 epochs) to get some good results.
- arguments
- batch_size : Define batch size (default=64)
- image_path : Path for lip image files (default='./data/datasets/')
- align_path : Path for align files (default='./data/align/')
- num_gpus : Num of gpus (if num_gpus is 0, then use cpu) (default=1)
- num_workers : Num of workers when generating data (default=0)
- data_type : 'train' or 'valid' (defalut='valid')
- model_path : Path of pretrained model (default=None)
python infer.py --model_path=$(model_path)
[Target]
['lay green with a zero again',
'bin blue with r nine please',
'set blue with e five again',
'bin green by t seven soon',
'lay red at d five now',
'bin green in x eight now',
'bin blue with e one now',
'lay red at j nine now']
[Pred]
['lay green with s zero again',
'bin blue with r nine please',
'set blue with e five again',
'bin green by t seven soon',
'lay red at c five now',
'bin green in x eight now',
'bin blue with m one now',
'lay red at j nine now']