physioex.models.sleepppgnet.SleepPPGNet#
- 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).
- __init__(n_classes=4, n_epochs=1200, samples_per_epoch=1024, class_order='physioex')[source]#
Initialize internal Module state, shared by both nn.Module and ScriptModule.
Methods
__init__([n_classes, n_epochs, ...])Initialize internal Module state, shared by both nn.Module and ScriptModule.
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Return the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(x)Return per-epoch logits of shape
(B, L, n_classes).from_original(checkpoint_path[, class_order])Load a replica checkpoint into a fresh
SleepPPGNet.get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules([remove_duplicate])Return an iterator over all modules in the network.
mtia([device])Move all model parameters and buffers to the MTIA.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
predict_night(signals[, metadata])Classify one whole night, already preprocessed by the
sleepppgnetpreset.register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post-hook to be run after module's
load_state_dict()is called.register_load_state_dict_pre_hook(hook)Register a pre-hook to be run before module's
load_state_dict()is called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_post_hook(hook)Register a post-hook for the
state_dict()method.register_state_dict_pre_hook(hook)Register a pre-hook for the
state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
set_submodule(target, module[, strict])Set the submodule given by
targetif it exists, otherwise throw an error.share_memory()state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
Attributes
T_destinationcall_super_initdump_patchestraining- 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