pyrtc.image_reconstructor
Turn wavefront-sensor images into the loop’s signal with a PyTorch model.
TorchImageReconstructor is an image-based reconstructor: it reads the
wfs image stream and publishes the output of a user-supplied PyTorch
model as the signal stream. It goes in the slopes section in place of
SlopesProcess, so the loop, the calibration
methods and the rest of the pipeline work unchanged. Typical uses are neural
reconstructors and focal-plane wavefront sensing, where a network maps pixels
straight to modal coefficients (run the loop with an identity interaction
matrix) or to any other signal the loop calibrates as usual.
Config (slopes section):
slopes:
class_name: TorchImageReconstructor
signal_size: 120 # elements of the model output
model_file: calib/reconstructor.pt2 # torch.export (.pt2) or TorchScript
# or a Python factory returning an nn.Module, plus optional weights:
# model_factory: my_models:build_cnn # "module:function"
# model_factory_file: models.py # then model_factory: build_cnn
# model_kwargs: {num_outputs: 120}
# state_dict_file: calib/weights.pt
device: cuda:0 # cpu (default), cuda, cuda:N
dtype: float32 # or float16 (CUDA only)
cuda_graph: true # capture the model; eager fallback
flux_normalization: sum # none (default), sum or mean
sqrt_stretch: false
output_scale_file: "" # .npy with signal_size factors
functions: [compute_signal]
The work is split in two: TorchModelRunner owns the model and the
real-time path (preprocessing, pinned host buffers, a dedicated CUDA stream,
CUDA-graph capture) and has no streams, so it can be benchmarked and tested
on its own; the component adds the stream wiring and timing.
torch is imported only when a reconstructor or runner is built, so
import pyrtc stays torch-free.
Module Attributes
|
Images whose normalisation flux is at or below this are treated as dark: the reconstructor publishes zeros instead of the model's response to noise. |
Functions
|
Build the model a reconstructor config describes (on the CPU). |
Classes
|
Publish a PyTorch model's output on each WFS image as the loop's signal. |
|
Run a PyTorch model on single WFS images, with optional CUDA graphs. |