Skip to main content

osf_rs/
lib.rs

1//! # osf-rs — OSF Sleep Foundation Model inference in Rust
2//!
3//! Pure-Rust inference for the OSF (Open Sleep Foundation) model,
4//! built on [Burn 0.20](https://burn.dev).
5//!
6//! OSF is a Vision Transformer (ViT) trained with DINO+iBOT self-distillation
7//! on 166,500 hours of polysomnography data. It produces general-purpose
8//! representations from 12-channel PSG signals (EEG, EOG, EMG, ECG, respiratory).
9//!
10//! ## Quick start
11//!
12//! ```rust,ignore
13//! use osf_rs::{OsfEncoder, ModelConfig};
14//!
15//! let (encoder, _ms) = OsfEncoder::<B>::load_with_config(
16//!     ModelConfig::default(),
17//!     Path::new("osf_backbone.safetensors"),
18//!     device,
19//! )?;
20//!
21//! let batch = osf_rs::build_batch::<B>(signal, 12, 1920, &device);
22//! let emb = encoder.run_batch(&batch)?;
23//! // emb.cls_emb: [768] — global epoch-level representation
24//! // emb.patch_embs: [90 * 768] — local patch representations
25//! ```
26
27pub mod config;
28pub mod data;
29pub mod encoder;
30pub mod model;
31pub mod weights;
32
33// Flat re-exports
34pub use encoder::OsfEncoder;
35pub use config::{ModelConfig, PSG_CHANNELS, NUM_PSG_CHANNELS, SAMPLE_RATE, EPOCH_SEC, EPOCH_SAMPLES};
36pub use data::{InputBatch, EpochEmbedding, EncodingResult, build_batch, channel_wise_normalize};