Phasic← Overview

Models and inference

Pane:       Inference
Requires:   `onnx` feature (off by default) + the ONNX runtime
Applies to: whatever channels the model's contract requires

Phasic can score a recording with a pretrained model and show the predictions alongside the signal — sleep stages across a night, seizure probability over a long EEG.

A model is data, not code

Phasic contains no model. It has no dependency on PyTorch, CUDA, or any model’s Python, and adding a model does not mean changing Phasic.

A model is an ordinary directory that Phasic reads at run time:

models/<name>/
  manifest.json      the contract — the only file Phasic parses
  <graph>.onnx       one or more ONNX graphs the manifest names
  _validate/         optional parity fixtures

The manifest is the whole interface. It states what the model expects — sample rate, window length, which channels in which order — and what it emits. Phasic reads it, maps your recording onto those requirements, runs the graph, and decodes the output.

A model that fits the existing contract needs no changes to Phasic at all.

What happens when you run one

  1. The contract is compiled against your recording. Phasic works out which of your channels satisfy each group the model requires. This can fail, and failing here is the point — see below
  2. The recording is preprocessed to the model’s stated rate and normalization
  3. The signal is cut into windows at the model’s window length and stride
  4. Each window is scored, in batches, on a background thread
  5. Outputs are decoded into predictions against the recording’s timeline

A model that cannot be satisfied is refused

If the recording lacks what the contract requires, Phasic says so by name rather than running anyway.

This is the most important behaviour in this chapter. A sleep-staging model needs brain signal; given a polysomnography recording with no EEG, the honest answer is a refusal naming the missing group. The alternative — padding the absent channels with zeros and scoring anyway — produces confident predictions from a tensor that is largely silence, and nothing about the result would look wrong.

Where a model tolerates absent channels, the contract says so explicitly, and padded rows are flagged so the model knows they are not signal.

Channel matching

Models differ in how strictly they need channels identified, and the contract distinguishes these cases:

Selection Meaning
By kind “Two EOG channels, any two.” Correct when montages vary between sites
By name “Exactly C3, C4, O1, O2, in that order.” Required for models trained on a fixed electrode layout
Name then kind Named channels first, remaining rows filled by kind
Alias set A membership test against a table of known labels, taken in recording order

Name matching is normalised, so a channel labelled EEG C3-M2 satisfies a contract asking for C3. Real recordings decorate their labels with the reference, and requiring an exact string match would reject files that are perfectly valid.

Selecting by name matters more than it might appear: for a model trained on a fixed layout, feeding O1 into C3’s row is silent nonsense that no amount of kind-matching would catch.

Licensing

Models carry their own licenses, which are not Phasic’s. Some are restricted — a non-commercial license is a constraint you are obliged to know about, so the manifest records it and Phasic surfaces it rather than leaving it in a repository you never read.

See the model zoo for the terms of each model.

This is also why Phasic does not include models: a non-commercial model may not be redistributed as part of a commercial product. Get models downloads each model from its authors and converts it on your computer, after you accept its licence (Obtaining models).

Pages