An event camera processing library with Rust backend and Python bindings, designed for scalable data processing with real-world event camera datasets.
Core Features
- Universal Format Support: Load data from H5, AEDAT, EVT2/3, AER, and text formats
- Automatic Format Detection: No need to specify format types manually
- Polars DataFrame Integration: High-performance DataFrame operations with up to 360M events/s filtering
- Event Filtering: Comprehensive filtering with temporal, spatial, and polarity options
- Event Representations: Stacked histograms, voxel grids, and mixed density stacks
- Neural Network Models: E2VID model loading and inference
- Real-time Data Processing: Handle large datasets (550MB+ files) efficiently
- Polarity Encoding: Automatic conversion between 0/1 and -1/1 polarities
- Rust Performance: Memory-safe, high-performance backend with Python bindings
In Development: Advanced neural network processing (hopefully with Rust
backend, maybe Candle) Real-time visualization (Only simulated working at the
moment — see wasm-evlib
)
Note: The Rust backend currently focuses on data loading and processing, with Python modules providing advanced features like filtering and representations.
- Quick Start
- Installation
- Polars DataFrame Integration
- Available Python Modules
- High-Performance PyTorch DataLoader
- Examples
- Development
- Community & Support
- License
Quick Start
Basic Usage
# Load events from any supported format (automatic detection)
=
# Or load as LazyFrame for memory-efficient processing
=
# Basic event information
# Convert to NumPy arrays for compatibility
=
=
=
=
Advanced Filtering
# Load events as LazyFrame for efficient processing
=
# Time filtering using Polars operations
=
# Spatial filtering (Region of Interest)
=
# Polarity filtering
=
# Collect final results
=
Event Representations
evlib provides comprehensive event representation functions for computer vision and neural network applications:
# Load events and create representations
=
=
# Create stacked histogram (replaces RVT preprocessing)
=
# Create mixed density stack representation
=
# Create voxel grid representation
=
# Advanced representations (require data type conversion)
# Convert timestamp and ensure proper dtypes for advanced functions
=
=
# Create time surface representation
=
# Create averaged time surface
=
Installation
Basic Installation
# For Polars DataFrame support (recommended)
# For PyTorch integration
Development Installation
We recommend using uv for fast, reliable Python package management:
# Install uv (if not already installed)
|
# Clone the repository
# Create virtual environment and install dependencies
# Build the Rust extensions
System Dependencies
# Ubuntu/Debian
# macOS
Performance-Optimized Installation
For optimal performance, ensure you have the recommended system configuration:
System Requirements:
- RAM: 8GB+ recommended for files >100M events
- Python: 3.10+ (3.12 recommended for best performance)
- Polars: Latest version for advanced DataFrame operations
Installation for Performance:
# Install with Polars support (recommended)
# For development with all performance features (using uv)
# Verify installation with benchmark
Optional Performance Dependencies:
# For advanced memory monitoring
# For parallel processing (already included in dev)
Polars DataFrame Integration
evlib provides comprehensive Polars DataFrame support for high-performance event data processing:
Key Benefits
- Performance: 1.9M+ events/s loading speed, 360M+ events/s filtering speed
- Memory Efficiency: ~23 bytes/event (5x better than typical 110 bytes/event)
- Expressive Queries: SQL-like operations for complex data analysis
- Lazy Evaluation: Query optimization for better performance
- Ecosystem Integration: Seamless integration with data science tools
API Overview
Loading Data
# Load as LazyFrame (recommended)
=
= # Collect to DataFrame when needed
# Automatic format detection and optimization
= # EVT2 format automatically detected
Advanced Features
# Chain operations with LazyFrames for optimal performance
=
=
# Memory-efficient temporal analysis
=
# Complex filtering operations with Polars
=
=
Utility Functions
# Built-in format detection
=
# Spatial filtering using Polars operations
=
=
# Chain multiple filters efficiently
=
# Temporal analysis with Polars operations
=
# Save processed data (working example)
=
=
=
, , , =
# Convert Duration microseconds to seconds for save function
= / 1_000_000
Performance Benchmarks
Benchmark Results:
- Loading Speed: 1.9M+ events/second average across formats
- Filter Speed: 360M+ events/second for complex filtering operations
- Memory Efficiency: ~23 bytes/event
- Format Performance: RAW binary (2.6M events/s) > HDF5 (2.5M events/s) > Text (0.6M events/s)
Benchmarking and Monitoring
Run performance benchmarks to verify optimizations:
# Verify README performance claims and generate plots
# Memory efficiency benchmark
# Test with your own data
Performance Examples
Optimal Loading for Different File Sizes
# Small files (<5M events) - Direct loading
=
=
# Large files (>5M events) - Automatic streaming
=
# Same API, automatically uses streaming for memory efficiency
# Memory-efficient filtering on large datasets using Polars
=
=
# Collect only when needed for memory efficiency
=
Memory Monitoring
=
return . / 1024 / 1024 # MB
# Monitor memory usage during loading
=
=
=
=
Troubleshooting Large Files
Memory Constraints
- Automatic Streaming: Files >5M events use streaming by default
- LazyFrame Operations: Memory-efficient processing without full materialization
- Memory Monitoring: Use
benchmark_memory.py
to track usage - System Requirements: Recommend 8GB+ RAM for files >100M events
Performance Tuning
- Optimal Chunk Size: System automatically calculates based on available memory
- LazyFrame Operations: Use
.lazy()
for complex filtering chains - Memory-Efficient Formats: RAW binary formats provide best performance, followed by HDF5
- Progress Reporting: Large files show progress during loading
Common Issues and Solutions
Issue: Out of memory errors
# Solution: Use filtering before collecting (streaming activates automatically)
=
# Streaming activates automatically for files >5M events
# Apply filtering before collecting to reduce memory usage
=
= # Only collect when needed
# Or stream to disk using Polars
Issue: Slow loading performance
# Solution: Use LazyFrame for complex operations
=
# Use Polars operations for optimized filtering
=
=
# Or chain Polars operations
=
Issue: Memory usage higher than expected
# Solution: Monitor and verify optimization
=
=
# Check format detection
=
Available Python Modules
evlib provides several Python modules for different aspects of event processing:
Core Modules
evlib.formats
: Direct Rust access for format loading and detectionevlib.filtering
: High-performance event filtering with Polarsevlib.representations
: Event representations (stacked histograms, voxel grids)evlib.models
: Neural network model loading and inference (Under construction)
Module Overview
# Core event loading (returns Polars LazyFrame)
=
# Format detection and description
=
=
# Advanced filtering using Polars operations
=
=
# Event representations (working examples)
=
=
=
# Advanced representations (with proper data conversion)
=
=
=
# Neural network models (limited functionality)
# If available
# Data saving (working examples)
=
=
, , , =
# Convert Duration microseconds to seconds for save functions
= / 1_000_000
High-Performance PyTorch DataLoader
evlib includes an optimized PyTorch dataloader implementation that showcases best practices for event camera data processing:
Key Features
- Polars → PyTorch Integration: Native
.to_torch()
conversion for zero-copy data transfer - RVT Preprocessing: Loads real RVT (Recurrent Vision Transformer) preprocessed data
- Statistical Feature Extraction: Efficiently extracts 91 features from stacked histograms
- High Throughput: Achieves 13,000+ samples/sec training throughput
- Memory Efficient: Lazy evaluation and batched processing
Quick Start
# New: Use the built-in PyTorch integration
# Option 1: One-liner for RVT data
=
# Option 2: Manual setup for custom transforms
=
# Option 3: Raw event data
=
=
# Define transform to extract features and labels from LazyFrame
"""Transform to separate RVT features and labels from Polars batch"""
=
# Add all temporal bin features (mean, std, max, nonzero for each bin)
= f
# Add bounding box features
# Add activity features
# Add normalized features
# Stack into feature matrix and extract labels
= # Shape: (batch_size, 91)
= # Shape: (batch_size,)
return
# Create efficient dataloader with transform
=
=
# Train with real event camera data
= # Shape: (256, 91) - 91 statistical features
= # Shape: (256,) - object class labels
# Your PyTorch training loop here
=
=
# ... backward pass, optimizer step, etc.
Architecture Overview
RVT HDF5 Data → Feature Extraction → Polars LazyFrame → .to_torch() → PyTorch Training
The dataloader demonstrates:
- Loading compressed HDF5 event representations (1198 samples, 20 temporal bins, 360×640 resolution)
- Statistical feature extraction (mean, std, max, nonzero) per temporal bin
- Object detection labels with bounding boxes and confidence scores
- Polars LazyFrame operations for memory-efficient processing
- Native PyTorch tensor conversion for optimal performance
Performance Benefits
- 95%+ accuracy on real 3-class classification tasks
- 13,262 samples/sec training throughput
- Memory efficient processing of large event datasets
- Zero-copy conversion between Polars and PyTorch
See examples/polars_pytorch_simplified.py
for the complete implementation and adapt it for your own event camera datasets.
Examples
Run examples:
# Test all notebooks
# Run specific examples
# Run the high-performance PyTorch dataloader example
Development
Testing
Core Testing
# Run all tests (Python and Rust)
# Test specific modules
# Test notebooks (including examples)
# Test with coverage
Documentation Testing
All code examples in the documentation are automatically tested to ensure they work correctly:
# Test all documentation examples
# Test specific documentation file
# Use the convenient test script
# Test specific documentation section
Code Quality
# Format code
# Run linting
# Check types
Building
Requirements
- Rust: Stable toolchain (see
rust-toolchain.toml
) - Python: ≥3.10 (3.12 recommended)
- Maturin: For building Python extensions
# Development build
# Build with features
# Release build
Community & Support
{ width=100% }
- GitHub: tallamjr/evlib
- Issues: Report bugs and request features
- Discussions: Community Q&A and ideas
License
MIT License - see LICENSE.md for details.