CoolFace
Apppublic

KenKaneki3/LipReading-AI

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
App README

LipNet โ€“ 3D CNN-LSTM Lip Reading Model ๐Ÿ‘„

Silent Video to Text using Deep Learning

A TensorFlow implementation of lip reading trained on the GRID corpus. The model watches silent video of a person's lips and transcribes what they're saying โ€” no audio required. Includes a full Streamlit web app for live demo.


Results

MetricValue
DatasetGRID Corpus (Speaker S1, ~500 videos)
Architecture3D CNN + Bidirectional LSTM (8.4M parameters)
Training100 epochs, CTC loss, Adam optimizer
Final training loss5.46
Final validation loss2.94
Word Error Rate (WER)11.61%

Sample predictions after 100 epochs:

Real:      place green by y five soon
Predicted: place green by y five soon  โœ…

Real:      lay blue at y zero please
Predicted: lay blue at y zero please   โœ…

Real:      bin green with b five soon
Predicted: bin green with b five soon  โœ…

Real:      bin red by m six now
Predicted: bin red by v six now        (1 word off)

Real:      set green in o seven soon
Predicted: set green in s seven soon   (1 word off)

Architecture

Input: 75-frame grayscale video (75 ร— 46 ร— 140 ร— 1)
    โ”‚
    โ–ผ
Conv3D(128, 3ร—3ร—3) โ†’ ReLU โ†’ MaxPool3D(1ร—2ร—2)
Conv3D(256, 3ร—3ร—3) โ†’ ReLU โ†’ MaxPool3D(1ร—2ร—2)
Conv3D(75,  3ร—3ร—3) โ†’ ReLU โ†’ MaxPool3D(1ร—2ร—2)
    โ”‚
    โ–ผ
TimeDistributed(Flatten)
    โ”‚
    โ–ผ
Bidirectional LSTM(128) โ†’ Dropout(0.5)
Bidirectional LSTM(128) โ†’ Dropout(0.5)
    โ”‚
    โ–ผ
Dense(vocab_size + 1, softmax)
    โ”‚
    โ–ผ
CTC Decode โ†’ Text output

Streamlit App

A full web interface for running predictions on any GRID video.

bash
cd app
streamlit run streamlitapp.py

The app lets you select any video from the dataset and shows:

  • โ€”The original video (converted to mp4)
  • โ€”The cropped lip region the model sees (as a GIF)
  • โ€”The raw token output from the model
  • โ€”The final decoded text prediction

Setup

Prerequisites

  • โ€”Python 3.10+
  • โ€”TensorFlow 2.x
  • โ€”Google Colab (recommended for training โ€” requires GPU)

Dataset

Download the GRID corpus (Speaker S1) from the official source:

  • โ€”Videos: http://spandh.dcs.shef.ac.uk/gridcorpus/
  • โ€”Place videos in data/s1/ and alignment files in data/alignments/s1/

Install dependencies

bash
pip install tensorflow opencv-python matplotlib imageio streamlit gdown numpy

Run the notebook

Open LipNet.ipynb in Google Colab with T4 GPU runtime enabled.

To use pre-trained weights, download checkpoint.weights.h5 and load:

python
model.load_weights('models/checkpoint.weights.h5')

Project Structure

LipReading_AI/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ streamlitapp.py      # Streamlit web interface
โ”‚   โ”œโ”€โ”€ modelutil.py         # Model architecture + weight loading
โ”‚   โ””โ”€โ”€ utils.py             # Video preprocessing + alignment loading
โ”œโ”€โ”€ models/
โ”‚   โ””โ”€โ”€ checkpoint.weights.h5
โ”œโ”€โ”€ LipNet.ipynb             # Training notebook
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

Data Pipeline

Each video is processed as follows:

  • โ€”Frames extracted via OpenCV, converted to grayscale
  • โ€”Lip region cropped: frame[190:236, 80:220] โ†’ resized to 46ร—140
  • โ€”Padded or truncated to exactly 75 frames
  • โ€”Normalized: (frames - mean) / std

Alignment files are parsed to extract spoken words, filtered for silence tokens (sil), and converted to character-level integer sequences for CTC training.


Training Details

  • โ€”Loss: CTC (Connectionist Temporal Classification) โ€” handles variable-length sequence alignment without requiring frame-level labels
  • โ€”Optimizer: Adam, initial lr=0.0001, exponential decay after epoch 30
  • โ€”Batch size: 2 (constrained by GPU memory)
  • โ€”Train/test split: 450 / 50 batches

Limitations

  • โ€”Trained on a single speaker (S1) โ€” will not generalize to unseen speakers without retraining
  • โ€”GRID corpus uses a constrained vocabulary (~50 words) โ€” not suitable for open-vocabulary lip reading
  • โ€”To improve generalization: add more GRID speakers (s2, s3, ...) or fine-tune on LRW dataset

Tech Stack

  • โ€”TensorFlow / Keras โ€” model training and CTC loss
  • โ€”OpenCV โ€” video frame extraction and preprocessing
  • โ€”NumPy โ€” array manipulation and WER calculation
  • โ€”Streamlit โ€” web app interface
  • โ€”Google Colab โ€” T4 GPU training environment

License

MIT