blinklinmult.paper.session¶
Running a frozen ONNX graph, with numpy and onnxruntime alone.
No torch here, and none reachable from here. That is the whole point of shipping
the 1.x models as graphs: their inference path cannot be broken by a PyTorch
upgrade, a linmult release, or anything else this repository does later.
The class is deliberately thin. It holds a session, remembers what the graph’s
inputs are called, and returns numpy arrays –
BlinkDetector supplies the normalisation and the
event extraction on top, exactly as it does for the PyTorch-backed v2 model.
Attributes¶
Module-level logger. |
|
Per-channel mean the 1.x models were trained against. |
|
Per-channel standard deviation. See |
|
Name of the eye-crop input in every exported graph. |
|
Name of the descriptor input, present only in the two-stream graph. |
|
Name of the per-frame output in every exported graph. |
|
Name of the pooled output, present only in the two-stream graph. |
Exceptions¶
Raised when a graph cannot be loaded or is fed the wrong inputs. |
Classes¶
A frozen 1.x model, backed by an |
Functions¶
|
Open an exported graph. |
Module Contents¶
- blinklinmult.paper.session.logger¶
Module-level logger.
- blinklinmult.paper.session.IMAGENET_MEAN: tuple[float, float, float] = (0.485, 0.456, 0.406)¶
Per-channel mean the 1.x models were trained against.
Torchvision’s standard ImageNet normalisation, applied after a bicubic resize to 64x64. The v2
BlinkCNNuses plain/255instead; the two are not interchangeable, and applying the wrong one degrades accuracy without erroring.
- blinklinmult.paper.session.IMAGENET_STD: tuple[float, float, float] = (0.229, 0.224, 0.225)¶
Per-channel standard deviation. See
IMAGENET_MEAN.
- blinklinmult.paper.session.CROPS_INPUT = 'crops'¶
Name of the eye-crop input in every exported graph.
- blinklinmult.paper.session.FEATURES_INPUT = 'features'¶
Name of the descriptor input, present only in the two-stream graph.
- blinklinmult.paper.session.SEQUENCE_OUTPUT = 'sequence'¶
Name of the per-frame output in every exported graph.
- blinklinmult.paper.session.CLIP_OUTPUT = 'clip'¶
Name of the pooled output, present only in the two-stream graph.
- exception blinklinmult.paper.session.SessionError[source]¶
Bases:
ExceptionRaised when a graph cannot be loaded or is fed the wrong inputs.
Initialize self. See help(type(self)) for accurate signature.
- class blinklinmult.paper.session.OnnxModel(session: onnxruntime.InferenceSession, metadata: dict[str, Any] | None = None)[source]¶
A frozen 1.x model, backed by an
onnxruntimesession.- Parameters:
session (ort.InferenceSession) – The loaded graph.
metadata (dict[str, Any]) – Its sidecar, if one was found beside it.
- property needs_features: bool¶
Whether this graph takes the 160-d descriptor stream.
- __call__(crops: numpy.ndarray, features: numpy.ndarray | None = None) dict[str, numpy.ndarray][source]¶
Run the graph.
- Parameters:
crops (np.ndarray) –
(B, T, 3, H, W)float32, already normalised.features (np.ndarray | None) –
(B, T, 160)float32, for the two-stream graph.
- Returns:
- Output name to array. Always carries
"sequence"(B, T, 1); the two-stream graph also carries"clip"(B, 1).
- Return type:
dict[str, np.ndarray]
- Raises:
SessionError – If a required input is missing.
- blinklinmult.paper.session.load_onnx(path: str | pathlib.Path, providers: list[str] | None = None) OnnxModel[source]¶
Open an exported graph.
- Parameters:
path (str | Path) – The
.onnxfile. A.onnx.jsonsidecar beside it is read if present.providers (list[str] | None) – Execution providers, in preference order. Defaults to
onnxruntime’s own choice.
- Returns:
Ready to run.
- Return type:
- Raises:
SessionError – If the file is missing, or
onnxruntimeis not installed.