Skip to main content

LASER ASD - Lip Landmark Assisted Speaker Detection for Active Speaker Detection

Project description

LASER ASD - Lip Landmark Assisted Speaker Detection

PyPI version Python 3.8+ License: MIT

A PyTorch implementation of LASER ASD for Active Speaker Detection, providing a simple interface for the LoCoNet encoder with LASER landmark injection.

Features

  • Active Speaker Detection using audio-visual fusion
  • Based on LoCoNet architecture with LASER landmark injection
  • Simple Python API for inference
  • GPU acceleration with CUDA support
  • Compatible with PyTorch 1.10+

Installation

pip install laser-asd

Quick Start

import numpy as np
from laser_asd import LaserASDModel

# Initialize model
model = LaserASDModel(device="cuda")

# Load pre-trained weights
model.load_weights("/path/to/loconet_laser.model")

# Prepare inputs
# face_crops: numpy array of shape [T, H, W, C] or [T, H, W]
# audio_data: numpy array of shape [samples] at 16kHz
face_crops = np.random.rand(100, 112, 112, 3).astype(np.float32)
audio_data = np.random.rand(64000).astype(np.float32)  # 4 seconds at 16kHz

# Predict speaking scores
scores = model.predict(face_crops, audio_data, sample_rate=16000, fps=25.0)

# scores >= 0 indicates speaking
is_speaking = scores >= 0

Model Weights

Pre-trained model weights can be downloaded from:

Set the model path via environment variable:

export LASER_ASD_MODEL_PATH=/path/to/loconet_laser.model

Or pass it directly:

model = LaserASDModel(device="cuda", model_path="/path/to/loconet_laser.model")

API Reference

LaserASDModel

class LaserASDModel:
    def __init__(
        self,
        device: str = "cuda",
        model_path: Optional[Path] = None,
        use_landmarks: bool = False,
    ):
        """
        Initialize LASER ASD model.

        Args:
            device: Device to run model on ('cuda' or 'cpu')
            model_path: Path to model weights file
            use_landmarks: Whether to use landmark features (False uses zeros)
        """

    def load_weights(self, model_path: Optional[str] = None):
        """Load model weights."""

    def predict(
        self,
        face_crops: np.ndarray,
        audio_data: np.ndarray,
        sample_rate: int = 16000,
        fps: float = 25.0,
    ) -> np.ndarray:
        """
        Predict speaking probability for each frame.

        Args:
            face_crops: Face crop images [T, H, W, C] or [T, H, W]
            audio_data: Audio waveform [samples]
            sample_rate: Audio sample rate (default: 16000)
            fps: Video frame rate (default: 25.0)

        Returns:
            Per-frame speaking scores [T] (>= 0 means speaking)
        """

Factory Function

def create_laser_model(
    device: str = "cuda",
    model_path: Optional[str] = None,
    **kwargs,
) -> LaserASDModel:
    """Factory function to create LASER ASD model."""

Requirements

  • Python >= 3.8
  • PyTorch >= 1.10.0
  • torchvision >= 0.11.0
  • numpy >= 1.20.0
  • opencv-python >= 4.5.0
  • resampy >= 0.4.0
  • python_speech_features >= 0.6

Citation

If you use this code, please cite the original LASER ASD paper:

@inproceedings{nguyen2024laser,
  title={LASER: Lip Landmark Assisted Speaker Detection},
  author={Nguyen, Phat Lam and others},
  booktitle={Proceedings},
  year={2024}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

laser_asd-0.1.0.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

laser_asd-0.1.0-py3-none-any.whl (61.7 kB view details)

Uploaded Python 3

File details

Details for the file laser_asd-0.1.0.tar.gz.

File metadata

  • Download URL: laser_asd-0.1.0.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for laser_asd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7af961e9e84d53247c51a083d288734956899a235a2b99740b615b663de70b62
MD5 c94ec2497cc698392dbdfb095e9d342a
BLAKE2b-256 53ff1ab5beca53fa87469e5b8fedcecad1715aa17574dab5b34eca2a603557e8

See more details on using hashes here.

File details

Details for the file laser_asd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: laser_asd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 61.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for laser_asd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c576dbb4d26530300b96fcba7fb5516956f13988fb5d5926e6ba8427d2d819c2
MD5 134a139a98e3d05a6426d01cd7bf54b8
BLAKE2b-256 1d8aa59aa8967a7185fe140003d67f08cb1121a84c1527114bbc25b14e91ae6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page