Skip to main content

EEG emotion recognition with CNN-Transformer encoders and three-stage hierarchical classifiers

Project description

DGLZ

EEG emotion recognition with CNN-Transformer encoders and three-stage hierarchical classifiers.

Overview

DGLZ is a Python toolkit for EEG-based emotion recognition. It combines convolutional neural network (CNN) feature extractors with Transformer encoders to model both local and global temporal patterns in EEG signals. A three-stage hierarchical classification pipeline progressively refines emotion predictions.

Key components:

  • Data processing -- EEG I/O, channel selection, band filtering, signal transforms, and index building.
  • Resampling -- Truncated-Gaussian and subject-state-aware resampling strategies for balanced training data.
  • Datasets -- PyTorch-style dataset classes for resampled, subject-state, normal-emotion, and depression-emotion data with configurable collation and splitting.
  • Models -- CNN blocks, Transformer blocks, token embeddings, and specialised encoder architectures for trial-level, subject-state, normal-emotion, and depression-emotion classification.
  • Training -- Loss functions, optimizers, schedulers, early stopping, checkpointing, and metric tracking.
  • Prediction -- Post-processing, prediction aggregation, three-stage inference pipeline, and submission formatting.
  • CLI -- A unified eemo command-line interface built on Typer.

Installation

Requires Python 3.13 or later.

# Clone the repository
git clone https://github.com/SuShuHeng/DGLZ.git
cd DGLZ

# Install in editable (development) mode
pip install -e .

# Or with all optional dependencies (test + packaging tools)
pip install -e ".[all]"

Updating

# Check and update from PyPI, fallback to GitHub Release (default)
eemo update

# Update from GitHub Release only (skip PyPI)
eemo update --dist-repo

# Install a specific version from GitHub Release
eemo update --dist-repo --tag v0.1.2

# Use a custom distribution repository
eemo update --dist-repo --dist-repo-url https://github.com/example/repo.git --tag v0.1.2

# Use a custom wheel filename pattern
eemo update --dist-repo --tag v0.1.2 --asset-pattern "dglz-*.whl"

# Preview without installing
eemo update --dry-run

CLI Usage

After installation the eemo command is available:

# Show available commands
eemo --help

# Prepare raw EEG data for processing
eemo prepare --help

# Resample datasets for balanced training
eemo resample --help

# Train a model
eemo train --help

# Run the three-stage hierarchical inference pipeline
eemo infer-three-stage --help

# Run predictions with a trained model
eemo pred --help

# Display the current version
eemo version

# Manage configuration files
eemo config --help

# Run experiment training sweeps
eemo exp-train --help

# Run experiment prediction sweeps
eemo exp-pred --help

# Manage model checkpoints
eemo ckpt --help

Project Structure

DGLZ/
├── pyproject.toml          # Package metadata and build configuration
├── README.md               # This file
├── .python-version         # Python version pin (3.13)
├── configs/                # Configuration files
├── docs/                   # Documentation
├── src/
│   └── eemoclas/           # Main package
│       ├── __init__.py
│       ├── __version__.py
│       ├── cli/            # Command-line interface
│       │   └── main.py     # Entry point (registers as `eemo`)
│       ├── data/           # EEG I/O, splitting, transforms
│       ├── datasets/       # PyTorch dataset classes
│       ├── model/          # CNN-Transformer architectures
│       ├── prediction/     # Inference and post-processing
│       ├── resampling/     # Data resampling strategies
│       ├── training/       # Training loop utilities
│       └── utils/          # Configuration, logging, metrics, paths
└── tests/                  # Test suite

Running Tests

pip install -e ".[test]"
pytest

License

Licensed under the Apache License 2.0.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

dglz-0.1.24.post2.tar.gz (442.5 kB view details)

Uploaded Source

Built Distribution

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

dglz-0.1.24.post2-py3-none-any.whl (410.9 kB view details)

Uploaded Python 3

File details

Details for the file dglz-0.1.24.post2.tar.gz.

File metadata

  • Download URL: dglz-0.1.24.post2.tar.gz
  • Upload date:
  • Size: 442.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for dglz-0.1.24.post2.tar.gz
Algorithm Hash digest
SHA256 fb63d93f0c9876b4e9e341c2a634b3e9b04b25b3bc5fb5a79bcca4ccb20931bd
MD5 a0d65f4fd324000d56bd473178246814
BLAKE2b-256 c8f3d877bdb1ca0e1665e09ce6dbc2d3023837cfaa45763692dd35732dce237e

See more details on using hashes here.

File details

Details for the file dglz-0.1.24.post2-py3-none-any.whl.

File metadata

  • Download URL: dglz-0.1.24.post2-py3-none-any.whl
  • Upload date:
  • Size: 410.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for dglz-0.1.24.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 a858ac6a22d44b9ddf3fb2470cab6e2efd855989b136f2a3979ea5e6a3957654
MD5 8dca52b26aa1bee9ceb2ecb4dff3cc12
BLAKE2b-256 7ad8bc0227dbd7a58609edfe7203da480da984a3f898a327d38008f93c0c07e7

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