SleepPPGNet (Kotzen et al., 2023) — replica weights#
SleepPPG-Net stages a whole night from a single PPG (photoplethysmogram) channel: a 1-D convolutional encoder over the continuous signal, a window layer that cuts it into 30-s epochs, a time-distributed dense layer and two dilated temporal convolution blocks. It predicts four classes (W, Light, Deep, REM).
Paper: SleepPPG-Net: A deep learning algorithm for robust sleep staging from continuous photoplethysmography, IEEE JBHI (2023), arXiv:2202.05735.
The authors did not release weights. physioex loads a third-party replica (
sleep-is-all-you-need/SPPPPG-Neton Hugging Face, retrained with the SleePyPhases framework). It is not the authors’ model, and its weights are licensed for fair non-commercial research use only;load_from_pretrainedwarns about this on every load.physioex class:
physioex.models.sleepppgnet:SleepPPGNet.
Quick start#
from physioex.data.datasets import get_dataset
from physioex.models import load_from_pretrained
from physioex.train import replication as rep
model = load_from_pretrained("sleepppgnet-replica", verbose=True)
data = get_dataset("mesa")(
channels=["PPG"],
pipelines="sleepppgnet",
sequence_length=0,
label_transform="aasm4",
trim_excess_wake=False,
)
test = data.get_splits(split="sleepppgnet-replica")[2]
for subject, signals, labels, metadata in rep.iter_nights(data, test[:1]):
stages = model.predict_night(signals) # (n_epochs,) in 0..3
The model output is permuted to the physioex class order (W, Light, Deep,
REM); class_order="original" keeps the replica’s order.
Inputs and preprocessing#
The sleepppgnet preset follows the replica’s preprocessing: an 8th-order
Chebyshev II low-pass at 8 Hz (-40 dB stop band), FFT resampling to 1024
samples per 30-s epoch (34.13 Hz), clipping at three standard deviations and
z-scoring; the night is padded or truncated to 1200 epochs (10 h).
Replication#
examples/pretrained/sleepppgnet/verify.py evaluates the replica on the 204
MESA test nights of its split (get_splits(split="sleepppgnet-replica")) with
the paper’s metric, the median per-recording kappa. It obtains 0.739 against
the paper’s 0.75. Since the weights are not the authors’, the number is
reported, not asserted.
Training#
physioex does not ship a training script for this model. The paper’s recipe is
summarised in examples/pretrained/sleepppgnet/TRAINING.md.
API#
- class physioex.models.sleepppgnet.SleepPPGNet(n_classes=4, n_epochs=1200, samples_per_epoch=1024, class_order='physioex')[source]
Bases:
ModuleSleepPPG-Net with a physioex per-epoch interface.
The submodule layout matches the replica’s
SleepPPGNetTorch(fe_layersx8,window_layer,td_dense,tcn1,tcn2,fc) so that a replica checkpoint loads withstrict=Trueand no remapping.- Parameters:
n_classes (int) – number of output classes (4).
n_epochs (int) – number of 30 s epochs in a full night (1200).
samples_per_epoch (int) – samples per epoch (1024, i.e. 32 Hz).
class_order (str) –
"physioex"permutes the replica’s output [Wake, REM, Light, Deep] to [W, Light, Deep, REM];"original"returns the replica order unchanged.
- Input:
A full night of
n_epochs * samples_per_epoch(1_228_800) samples, given as(B, n_epochs, samples_per_epoch),(B, n_epochs, 1, samples_per_epoch)(the physioex per-epoch format), or(B, 1, n_epochs * samples_per_epoch)(the original format).- Output:
Logits
(B, n_epochs, n_classes).
- forward(x)[source]
Return per-epoch logits of shape
(B, L, n_classes).xmay be(B, L, 1, S),(B, L, S)(physioex per-epoch) or(B, 1, T)(original format,T = n_epochs * samples_per_epoch). WhenL != n_epochsthe input is zero-padded at the end (or truncated) ton_epochsepochs before the network is run, and only the firstLepochs are returned.
- classmethod from_original(checkpoint_path, class_order='physioex')[source]
Load a replica checkpoint into a fresh
SleepPPGNet.The replica checkpoint is not a plain state dict, so it is loaded with
weights_only=False; astate_dict/modelwrapper, if present, is unwrapped before a strict load. The returned model is in eval mode.- Parameters:
- Return type:
- predict_night(signals, metadata=None)[source]
Classify one whole night, already preprocessed by the
sleepppgnetpreset.- Parameters:
signals (dict[str, np.ndarray]) – Mapping of signal name to a
(L, 1024)float array of one night; the night’s"PPG"channel is required. The night is zero-padded (or truncated) to the model’s fixedn_epochs(1200 for the released model) grid before the network runs, as in the authors’ code for nights shorter or longer than 10 h.metadata (dict | None) – Unused (kept for a common interface with the other cardiorespiratory models).
- Returns:
int64 class indices of shape
(L,)in the model’s class order ([W, Light, Deep, REM] forclass_order="physioex"). Runs undertorch.no_grad()in eval mode, batch of one, on the model’s current device.- Return type:
np.ndarray