Skip to main content

Emotion expression capture from multiple modalities.

Project description

Multimodal Emotion Expression Capture Amsterdam

github license badge RSD read the docs badge fair-software badge workflow scq badge workflow scc badge build cffconvert markdown-link-check DOI docker hub badge docker build badge black code style badge

mexca is an open-source Python package which aims to capture human emotion expressions from videos in a single pipeline.

How To Use Mexca

mexca implements the customizable yet easy-to-use Multimodal Emotion eXpression Capture Amsterdam (MEXCA) pipeline for extracting emotion expression features from videos. It contains building blocks that can be used to extract features for individual modalities (i.e., facial expressions, voice, and dialogue/spoken text). The blocks can also be integrated into a single pipeline to extract the features from all modalities at once. Next to extracting features, mexca can also identify the speakers shown in the video by clustering speaker and face representations. This allows users to compare emotion expressions across speakers, time, and contexts.

Please cite mexca if you use it for scientific or commercial purposes.

Quick Installation

Here, we explain briefly how to install mexca on your system. Detailed instructions can be found in the Installation Details section. mexca can be installed on Windows, macOS and Linux. We recommend Windows 10, macOS 12.6.x, or Ubuntu.

The package contains five components that must be explicitly installed [^1]. By default, only the base package is installed (which requires only a few dependencies). The components can still be used through Docker containers which must be downloaded from Docker Hub. We recommend this setup for users with little experience with installing Python packages or who simply want to quickly try out the package. Using the containers also adds stability to your program.

Requirements

mexca requires Python version >= 3.7 and <= 3.9. It further depends on FFmpeg (for video and audio processing), which is usually automatically installed through the MoviePy package (i.e., its imageio dependency). In case the automatic install fails, it must be installed manually.

To download and run the components as Docker containers, Docker must be installed on your system. Instructions on how to install Docker Desktop can be found here.

All components but the VoiceExtractor depend on PyTorch (version 1.12). Usually, it should be automatically installed when specifying any of these components. In case the installation fails, see the installation instructions on the PyTorch web page.

For the SpeakerIdentifier component, the library libsndfile must also be installed on Linux systems.

The SentimentExtractor component depends on the sentencepiece library, which is automatically installed if Git is installed on the system.

Installation

We recommend installing mexca in a new virtual environment to avoid dependency conflicts. The base package can be installed from PyPI via pip:

pip install mexca

The dependencies for the additional components can be installed via:

pip install mexca[vid,spe,voi,tra,sen]

or:

pip install mexca[all]

The abbreviations indicate:

  • vid: FaceExtractor
  • spe: SpeakerIdentifier
  • voi: VoiceExtractor
  • tra: AudioTranscriber
  • sen: SentimentExtractor

To run the demo and example notebooks, install the Jupyter requirements via:

pip install mexca[demo]

Getting Started

If you would like to learn how to use mexca, take a look at our example notebook.

Note: mexca builds on pretrained models from the pyannote.audio package. Since release 2.1.1, downloading the pretrained models requires the user to accept two user agreements on Hugging Face hub and generate an authentication token. Therefore, to run the mexca pipeline, please accept the user agreements on here and here. Then, generate an authentication token here. Use this token to login to Hugging Face hub by running notebook_login() (from a jupyter notebook) or huggingface-cli login (from the command line). You only need to login when running mexca for the first time. See this link for details. When running container components, you need to supply the token excplicitly as value for the use_auth_token argument. We recommend storing the token on your system and accessing it from Python.

To create and apply the MEXCA pipeline with container components to a video file run the following code in a Jupyter notebook or a Python script (requires the base package and Docker):

from mexca.container import (
    AudioTranscriberContainer,
    FaceExtractorContainer,
    SentimentExtractorContainer,
    SpeakerIdentifierContainer,
    VoiceExtractorContainer,
)
from mexca.pipeline import Pipeline

# Set path to video file
filepath = 'path/to/video'

# Create standard pipeline with two faces and speakers
pipeline = Pipeline(
    face_extractor=FaceExtractorContainer(num_faces=2),
    speaker_identifier=SpeakerIdentifierContainer(
        num_speakers=2,
        use_auth_token="HF_TOKEN" # Replace this string with your token
    ),
    voice_extractor=VoiceExtractorContainer(),
    audio_transcriber=AudioTranscriberContainer(),
    sentiment_extractor=SentimentExtractorContainer()
)

# Apply pipeline to video file at `filepath`
result = pipeline.apply(
    filepath,
    frame_batch_size=5,
    skip_frames=5
)

# Print merged features
print(result.features)

The result should be a pandas data frame printed to the console or notebook output. Details on the output and extracted features can be found here.

Components

The pipeline components are described here.

Documentation

The documentation of mexca can be found on Read the Docs.

Contributing

If you want to contribute to the development of mexca, have a look at the contribution guidelines.

License

The code is licensed under the Apache 2.0 License. This means that mexca can be used, modified and redistributed for free, even for commercial purposes.

Credits

Mexca is being developed by the Netherlands eScience Center in collaboration with the Hot Politics Lab at the University of Amsterdam.

This package was created with Cookiecutter and the NLeSC/python-template.

[^1]: We explain the rationale for this setup in the Docker section.

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

mexca-0.5.0.tar.gz (74.2 kB view hashes)

Uploaded Source

Built Distribution

mexca-0.5.0-py3-none-any.whl (67.3 kB view hashes)

Uploaded Python 3

Supported by

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