CoolFace
Modelpublic

SamarthChugh/Custom-Face-Tracker-Model

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes7downloads
Model Card

πŸ§‘β€πŸ’» Deep Face Tracker (TensorFlow / Keras)

This repository hosts a custom deep face tracking model trained in TensorFlow / Keras. The model is designed to detect and track faces in real-time video streams, making it useful for applications such as:

  • β€”Face detection & tracking
  • β€”Eye/landmark tracking (extendable)
  • β€”Real-time video analysis

πŸ› οΈ Model Details

  • β€”Framework: TensorFlow / Keras (.keras format)
  • β€”Input: RGB image frames (preprocessed to the model’s training resolution, e.g., 120x120)
  • β€”Output:
  • β€”Bounding box coordinates
  • β€”Face presence classification

πŸ“₯ Usage

1. Load the model from Hugging Face Hub

python
import tensorflow as tf
from huggingface_hub import hf_hub_download

# Download model file
model_path = hf_hub_download(
    repo_id="your-username/face-tracker-tf",
    filename="face_tracker.keras"
)

# Load the model
model = tf.keras.models.load_model(model_path)

2. Run Inference on Frame

python
import cv2
import tensorflow as tf
import numpy as np
cap = cv2.VideoCapture(0)
while cap.isOpened():
  _, frame = cap.read()
  frame = frame[50:500, 50:500, :]

  rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  resized = tf.image.resize(rgb, (120,120))

  yhat = model.predict(np.expand_dims(resized/255,0))
  sample_coords = yhat[1][0]

  if yhat[0] > 0.5 :
    # control the main rectangle
    cv2.rectangle(frame,
                  tuple(np.multiply(sample_coords[:2], [450,450]).astype(int)),
                  tuple(np.multiply(sample_coords[2:], [450,450]).astype(int)),
                  color=(255,0,0), thickness=2)
    # control label rectangle
    cv2.rectangle(frame,
                  tuple(np.add(np.multiply(sample_coords[:2], [450,450]).astype(int), [0,-30])),
                  tuple(np.add(np.multiply(sample_coords[:2], [450,450]).astype(int), [80,0])),
                  color=(255,0,0), thickness=2)
    # controls the text rendered
    cv2.putText(frame, 'face', tuple(np.add(np.multiply(sample_coords[:2], [450,450]).astype(int), [0,-5])),
                cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2, cv2.LINE_AA)

  cv2.imshow('EyeTrack', frame)

  if cv2.waitKey(1) & 0xFF == ord('q'):
    break
  if cv2.getWindowProperty('EyeTrack', cv2.WND_PROP_VISIBLE) < 1:
    break

cap.release()
cv2.destroyAllWindows()

πŸ“Š Training

  • β€”Data: Custom labeled dataset (using Labelme)
  • β€”Augmentation: Albumentations for better generalization
  • β€”Losses: Combination of classification loss + localization loss
  • β€”Optimizer: Adam

⚠️ Limitations

  • β€”Works best on front-facing faces in controlled lighting
  • β€”Trained on a limited dataset (may not generalize perfectly in the wild)
  • β€”Not a replacement for production-grade trackers (e.g., MediaPipe FaceMesh, OpenCV Haar cascades)

πŸ“œ License

This model is shared for research and educational purposes. Please check licensing terms before using in commercial applications.


✨ Citation

latex
@misc{samarth2025facetracker,
  author       = {Samarth Chugh},
  title        = {Deep Face Tracker (TensorFlow/Keras)},
  year         = {2025},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/PredatorAlpha/Custom-Face-Tracker-Model}},
}