Preprocessing the LRS3 dataset involves four main stages. Assume the LRS3 data directory is ${lrs3} and contains pretrain, trainval, and test folders.
1. Data Preparation
Run lrs3_prepare.py to generate file lists and text labels. The --step flag determines the operation:
- Step 1: Splits long utterances in
pretraining into shorter ones and generates time boundaries/labels. - Step 2: Trims videos and audios based on new boundaries (uses
--rank and --nshard for sharding). - Step 3: Extracts audio for
trainval and test splits (uses --rank and --nshard). - Step 4: Generates file IDs and text transcriptions.
2. Facial Landmark Detection and Mouth ROI Cropping
This stage uses dlib to detect landmarks and align_mouth.py to crop the mouth regions. This generates mouth ROIs in ${lrs3}/video.
3. Frame Counting
Use count_frames.py to count audio/video frames. For Slurm users, count_frames_slurm.py can automate sharding and merging.
4. Manifest Generation
Use lrs3_manifest.py to set up the final data directory (e.g., for trainval-only or pretrain+trainval sets). This creates a tokenizer and target directories containing .tsv (manifests) and .wrd (text labels) files.
# 1. Data preparation
python lrs3_prepare.py --lrs3 ${lrs3} --ffmpeg /path/to/ffmpeg --rank ${rank} --nshard ${nshard} --step ${step}
# 2. Detect facial landmark and crop mouth ROIs
python detect_landmark.py --root ${lrs3} --landmark ${lrs3}/landmark --manifest ${lrs3}/file.list \
--cnn_detector /path/to/dlib_cnn_detector --face_detector /path/to/dlib_landmark_predictor --ffmpeg /path/to/ffmpeg \
--rank ${rank} --nshard ${nshard}
python align_mouth.py --video-direc ${lrs3} --landmark ${landmark_dir} --filename-path ${lrs3}/file.list \
--save-direc ${lrs3}/video --mean-face /path/to/mean_face --ffmpeg /path/to/ffmpeg \
--rank ${rank} --nshard ${nshard}
# 3. Count number of frames per clip
python count_frames.py --root ${lrs3} --manifest ${lrs3}/file.list --nshard ${nshard} --rank ${rank}
# 4. Set up data directory
python lrs3_manifest.py --lrs3 ${lrs3} --manifest ${lrs3}/file.list \
--valid-ids /path/to/valid --vocab-size ${vocab_size}