100 lines
3.2 KiB
Rust
100 lines
3.2 KiB
Rust
//! Deep Learning Artifact Detection with Explainability for MEG/EEG
|
|
//!
|
|
//! This crate provides transformer-based artifact detection using ONNX inference
|
|
//! with interpretable saliency maps to explain which channels and timepoints
|
|
//! contributed to artifact detection.
|
|
//!
|
|
//! # Features
|
|
//!
|
|
//! - **Multi-label artifact detection**: Eye blinks, muscle artifacts, heartbeat, etc.
|
|
//! - **ONNX inference**: High-performance inference with CPU/GPU/CoreML backends
|
|
//! - **Explainability**: Integrated Gradients, attention maps, SHAP values
|
|
//! - **Pre-trained models**: Ready-to-use models for common artifact types
|
|
//!
|
|
//! # Supported Artifact Types
|
|
//!
|
|
//! | Artifact | Description |
|
|
//! |----------|-------------|
|
|
//! | Eye Blink (EOG) | Blink artifacts in frontal channels |
|
|
//! | Eye Movement | Saccades and smooth pursuit artifacts |
|
|
//! | Muscle (EMG) | High-frequency muscle contamination |
|
|
//! | Heartbeat (ECG) | Cardiac artifact in MEG/EEG |
|
|
//! | Line Noise | 50/60 Hz power line interference |
|
|
//! | Movement | Head/body movement artifacts |
|
|
//!
|
|
//! # Architecture
|
|
//!
|
|
//! ```text
|
|
//! Input: [batch, channels, time]
|
|
//! │
|
|
//! ┌──────▼──────┐
|
|
//! │ 1D Conv │ Feature extraction
|
|
//! │ Encoder │
|
|
//! └──────┬──────┘
|
|
//! │
|
|
//! ┌──────▼──────┐
|
|
//! │ Transformer │ Self-attention over time
|
|
//! │ Encoder │
|
|
//! └──────┬──────┘
|
|
//! │
|
|
//! ┌──────▼──────┐
|
|
//! │ Multi-label │ Artifact classification
|
|
//! │ Classifier │
|
|
//! └──────┬──────┘
|
|
//! │
|
|
//! Output: [batch, n_artifact_types]
|
|
//! ```
|
|
//!
|
|
//! # Example
|
|
//!
|
|
//! ```rust,no_run
|
|
//! use rtx_neuro_artifacts::{ArtifactDetector, DetectorConfig, ArtifactType};
|
|
//!
|
|
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
//! // Create detector with default config
|
|
//! let config = DetectorConfig::default();
|
|
//! let detector = ArtifactDetector::new(config)?;
|
|
//!
|
|
//! // Detect artifacts in EEG segment [channels x time]
|
|
//! let eeg_data: Vec<Vec<f64>> = vec![vec![0.0; 1000]; 64];
|
|
//! let result = detector.detect(&eeg_data)?;
|
|
//!
|
|
//! // Check which artifacts were detected
|
|
//! for (artifact_type, probability) in result.predictions() {
|
|
//! if probability > 0.5 {
|
|
//! println!("{:?} detected with probability {:.2}", artifact_type, probability);
|
|
//! }
|
|
//! }
|
|
//!
|
|
//! Ok(())
|
|
//! }
|
|
//! ```
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
pub mod detector;
|
|
pub mod error;
|
|
pub mod explain;
|
|
pub mod labels;
|
|
pub mod models;
|
|
|
|
pub use detector::{ArtifactDetector, DetectionBatch, DetectionResult, DetectorConfig};
|
|
pub use error::{ArtifactError, ArtifactResult};
|
|
pub use explain::{
|
|
ArtifactExplainer, AttentionMap, ChannelImportance, ExplainerConfig, ExplanationResult,
|
|
SaliencyMap,
|
|
};
|
|
pub use labels::{ArtifactLabel, ArtifactRegion, ArtifactType};
|
|
pub use models::{ModelInfo, ModelRegistry, ModelSource, download_model};
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_crate_compiles() {
|
|
// Smoke test - crate structure is sound
|
|
assert!(true);
|
|
}
|
|
}
|