Skip to main content

BlinkLinMulT: Transformer-based Eye Blink Detection.

Project description

BlinkLinMulT

License python pytorch

BlinkLinMulT is trained for blink presence detection and eye state recognition tasks. Our results demonstrate comparable or superior performance compared to state-of-the-art models on 2 tasks, using 7 public benchmark databases.

Setup

Install package from PyPI for inference

pip install blinklinmult

Install package from PyPI for inference with preprocessing

conda create -n blink python=3.11
conda activate blink
pip install blinklinmult

Install package for training

git clone https://github.com/fodorad/BlinkLinMulT
cd BlinkLinMulT
pip install -e .[all]
pip install -U -r requirements.txt
python -m unittest discover -s test

Supported extras definitions:

extras tag description
dev dependencies for training the model from scratch

Quick start

Load models from the paper with pre-trained weights

The pre-trained weights are loaded by default.

from blinklinmult.models import DenseNet121, BlinkLinT, BlinkLinMulT

model1 = DenseNet121()
model2 = BlinkLinT()
model3 = BlinkLinMulT()

In the next sessions there are more detailed examples with dummy data, e.g. a forward pass is performed, shapes are mentioned.

Inference with dummy data

Pre-trained DenseNet121 for eye state recognition. The forward pass is performed using an input image.

import torch
from blinklinmult.models import DenseNet121

# input shape: (batch_size, channels, height, width)
x = torch.rand((32, 3, 64, 64), device='cuda')
model = DenseNet121(output_dim=1, weights='densenet121-union').cuda()
y_pred = model(x)

# output shape: (batch_size, output_dimension)
assert y_pred.size() == torch.Size([32, 1])

Pre-trained BlinkLinT for blink presence detection and eye state recognition. The forward pass is performed using sequence of images.

import torch
from blinklinmult.models import BlinkLinT

# input shape: (batch_size, time_dimension, channels, height, width)
x = torch.rand((8, 15, 3, 64, 64), device='cuda')
model = BlinkLinT(output_dim=1, weights='blinklint-union').cuda()
y_seq = model(x)

# output shape: (batch_size, time_dimension, output_dimension)
assert y_seq.size() == torch.Size([8, 15, 1])

Pre-trained BlinkLinMulT for blink presence detection and eye state recognition. The forward pass is performed using sequence of images and sequence of high-level features.

import torch
from blinklinmult.models import BlinkLinMulT

# inputs with shapes: [(batch_size, time_dimension, channels, height, width), (batch_size, time_dimension, feature_dimension)]
x1 = torch.rand((8, 15, 3, 64, 64), device='cuda')
x2 = torch.rand((8, 15, 160), device='cuda')
model = BlinkLinMulT(input_dim=160, output_dim=1, weights='blinklinmult-union').cuda()
y_cls, y_seq = model([x1, x2])

# output shape: (batch_size, time_dimension, output_dimension)
assert y_seq.size() == torch.Size([8, 15, 1])
assert y_cls.size() == torch.Size([8, 1])

Related projects

exordium

Collection of preprocessing functions and deep learning methods. This repository contains revised codes for fine landmark detection (including face, eye region, iris and pupil landmarks), head pose estimation, and eye feature calculation.

(2022) LinMulT

General-purpose Multimodal Transformer with Linear Complexity Attention Mechanism. This base model is further modified and trained for various tasks and datasets.

(2022) PersonalityLinMulT for personality trait and sentiment estimation

LinMulT is trained for Big Five personality trait estimation using the First Impressions V2 dataset and sentiment estimation using the MOSI and MOSEI datasets.

Citation - BibTex

If you found our research helpful or influential please consider citing:

(2023) BlinkLinMulT for blink presence detection and eye state recognition

@Article{fodor2023blinklinmult,
  title = {BlinkLinMulT: Transformer-Based Eye Blink Detection},
  author = {Fodor, Ádám and Fenech, Kristian and Lőrincz, András},
  journal = {Journal of Imaging},
  volume = {9},
  year = {2023},
  number = {10},
  article-number = {196},
  url = {https://www.mdpi.com/2313-433X/9/10/196},
  PubMedID = {37888303},
  ISSN = {2313-433X},
  DOI = {10.3390/jimaging9100196}
}

(2022) LinMulT for personality trait and sentiment estimation

@InProceedings{pmlr-v173-fodor22a,
  title = {Multimodal Sentiment and Personality Perception Under Speech: A Comparison of Transformer-based Architectures},
  author = {Fodor, {\'A}d{\'a}m and Saboundji, Rachid R. and Jacques Junior, Julio C. S. and Escalera, Sergio and Gallardo-Pujol, David and L{\H{o}}rincz, Andr{\'a}s},
  booktitle = {Understanding Social Behavior in Dyadic and Small Group Interactions},
  pages = {218--241},
  year = {2022},
  editor = {Palmero, Cristina and Jacques Junior, Julio C. S. and Clapés, Albert and Guyon, Isabelle and Tu, Wei-Wei and Moeslund, Thomas B. and Escalera, Sergio},
  volume = {173},
  series = {Proceedings of Machine Learning Research},
  month = {16 Oct},
  publisher = {PMLR},
  pdf = {https://proceedings.mlr.press/v173/fodor22a/fodor22a.pdf},
  url = {https://proceedings.mlr.press/v173/fodor22a.html}
}

What's next

  • Preprocessed data hosting for easier reproduction and benchmarking
  • Add train and test scripts for various databases

Updates

  • 1.0.0: Release version. Inference only with pre-trained models.

Contact

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

blinklinmult-1.0.4.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

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

blinklinmult-1.0.4-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file blinklinmult-1.0.4.tar.gz.

File metadata

  • Download URL: blinklinmult-1.0.4.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for blinklinmult-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d17b8f079b49b62ff08c335089acb9aad0a94b8a6c6fbe576a55190717fece5b
MD5 0ef0633dcf64c81f09c6d18074fb6786
BLAKE2b-256 d62a6204187e726aeafdd8efd8556860dec7b4c72607764380b1da3a65624762

See more details on using hashes here.

File details

Details for the file blinklinmult-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: blinklinmult-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for blinklinmult-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2ba96f946f73a7434294f6710b7406040a27f1418840b8dead7bc90a194573f5
MD5 67723bac79b21ec32fceda50de5a7084
BLAKE2b-256 40822f855bdde2288546cc2d72c0bec5a72f1bf541608cfafc58ab1e97ab3844

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