Surrogate Networks
Neural networks that learn to predict PSFs from lens parameters, replacing
expensive ray tracing during training. These power PSFNetLens.
Fully-connected network that predicts PSF values from input parameters.
deeplens.surrogate.MLP
Bases: Module
Fully-connected network for low-frequency PSF prediction.
Predicts PSFs as flattened vectors using stacked linear layers with ReLU activations and a Sigmoid output. The output is L1-normalized so it sums to 1 (valid as a PSF energy distribution).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Number of input features (e.g., field angle + wavelength). |
required |
out_features
|
int
|
Number of output features (flattened PSF size). |
required |
hidden_features
|
int
|
Width of hidden layers. Defaults to 64. |
64
|
hidden_layers
|
int
|
Number of hidden layers. Defaults to 3. |
3
|
Source code in deeplens-src/deeplens/surrogate/mlp.py
forward
Forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x |
Tensor
|
L1-normalized output tensor of shape
|
Source code in deeplens-src/deeplens/surrogate/mlp.py
MLP with convolutional layers for spatial PSF prediction.
deeplens.surrogate.MLPConv
Bases: Module
MLP encoder plus convolutional decoder for high-resolution PSF prediction.
The MLP encoder maps the input features to a low-resolution feature map of
spatial size min(ks, 32), which a transposed-convolution decoder then
upsamples by powers of two to the target PSF size ks. The decoder output is
always Sigmoid-activated and L1-normalized over the two spatial dimensions so
each predicted PSF sums to one.
Reference
"Differentiable Compound Optics and Processing Pipeline Optimization for End-To-end Camera Design".
Attributes:
| Name | Type | Description |
|---|---|---|
ks |
int
|
Spatial size of the output PSF. |
ks_mlp |
int
|
Spatial size of the MLP feature map, |
channels |
int
|
Number of output channels. |
encoder |
Sequential
|
Linear encoder producing the feature map. |
decoder |
Sequential
|
Transposed-convolution upsampling decoder. |
activation |
Module
|
Activation module selected by |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Number of input features (e.g. field angle plus wavelength). |
required |
ks
|
int
|
Spatial size of the output PSF. When greater than 32 it must be a multiple of 32 (asserted), and in practice \(32 \cdot 2^n\) so the decoder upsamples by integer powers of two. |
required |
channels
|
int
|
Number of output channels. Defaults to 3. |
3
|
activation
|
str
|
Activation name, |
'relu'
|
Source code in deeplens-src/deeplens/surrogate/mlpconv.py
forward
Predict normalized PSFs from input feature vectors.
Encodes x into a (batch_size, channels, ks_mlp, ks_mlp) feature map,
upsamples it through the conv decoder, then applies Sigmoid and L1
normalization over the spatial dimensions so each PSF sums to one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
decoded |
Tensor
|
Normalized PSF tensor of shape
|
Source code in deeplens-src/deeplens/surrogate/mlpconv.py
Sinusoidal-activation network (SIREN) for representing high-frequency PSF detail.
deeplens.surrogate.siren.Siren
Bases: Module
Single SIREN (Sinusoidal Representation Network) layer.
A linear layer followed by a sine activation. Uses the initialization scheme from "Implicit Neural Representations with Periodic Activation Functions".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_in
|
int
|
Input dimension. |
required |
dim_out
|
int
|
Output dimension. |
required |
w0
|
float
|
Frequency multiplier for the sine activation. Defaults to 1.0. |
1.0
|
c
|
float
|
Constant controlling the weight initialization scale (non-first layers). Defaults to 6.0. |
6.0
|
is_first
|
bool
|
Whether this is the first layer (uses a different init scale). Defaults to False. |
False
|
use_bias
|
bool
|
Whether to include a bias term. Defaults to True. |
True
|
activation
|
Module or None
|
Custom activation module. Defaults to None, which uses |
None
|
Source code in deeplens-src/deeplens/surrogate/siren.py
init_
Initialize the layer weight in place with the SIREN scheme.
Fills weight uniformly in \([-w_{std}, w_{std}]\), where the std is
\(1/\text{dim}\) for the first layer and \(\sqrt{c/\text{dim}}/w_0\)
otherwise. The bias argument is accepted for API symmetry but left
unchanged (it stays at its zero-initialized value).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
Tensor
|
Weight tensor of shape |
required |
bias
|
Tensor or None
|
Bias tensor of shape |
required |
c
|
float
|
Constant controlling the initialization scale. |
required |
w0
|
float
|
Frequency multiplier for the sine activation. |
required |
Source code in deeplens-src/deeplens/surrogate/siren.py
forward
Forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
out |
Tensor
|
Output tensor of shape |
Source code in deeplens-src/deeplens/surrogate/siren.py
SIREN variant with feature modulation for conditioning on lens parameters.
deeplens.surrogate.ModulateSiren
ModulateSiren(
dim_in,
dim_hidden,
dim_out,
dim_latent,
num_layers,
image_width,
image_height,
w0=1.0,
w0_initial=30.0,
use_bias=True,
final_activation=None,
outermost_linear=True,
)
Bases: Module
Modulated SIREN for latent-conditioned image synthesis.
Combines a SIREN synthesizer network (mapping a fixed pixel-coordinate grid to
output values) with a modulator network that scales each synthesizer layer based
on a conditioning latent vector. Used to predict spatially-varying PSFs
conditioned on lens parameters. The output is always tanh-activated and reshaped
to an image regardless of the outermost_linear / final_activation settings.
Attributes:
| Name | Type | Description |
|---|---|---|
synthesizer |
ModuleList
|
SIREN sine layers plus the final output layer. |
modulator |
ModuleList
|
Per-layer Linear+ReLU blocks producing modulation vectors from the latent (and previous modulation). |
grid |
Tensor
|
Registered coordinate buffer of shape
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_in
|
int
|
Input coordinate dimension (typically 2 for x, y). |
required |
dim_hidden
|
int
|
Hidden layer width for both synthesizer and modulator. |
required |
dim_out
|
int
|
Output dimension per pixel (e.g., 1 for grayscale PSF). |
required |
dim_latent
|
int
|
Dimension of the conditioning latent vector. |
required |
num_layers
|
int
|
Number of SIREN + modulator layers (excluding the final output layer of the synthesizer). |
required |
image_width
|
int
|
Output image width in pixels. |
required |
image_height
|
int
|
Output image height in pixels. |
required |
w0
|
float
|
Frequency multiplier for hidden sine layers. Defaults to 1.0. |
1.0
|
w0_initial
|
float
|
Frequency multiplier for the first sine layer. Defaults to 30.0. |
30.0
|
use_bias
|
bool
|
Whether to use bias in sine layers. Defaults to True. |
True
|
final_activation
|
Module or None
|
Activation for the final
|
None
|
outermost_linear
|
bool
|
If True, the final synthesizer layer is a
plain |
True
|
Source code in deeplens-src/deeplens/surrogate/modulate_siren.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
forward
Synthesize a batch of images from conditioning latent vectors.
Runs the shared coordinate grid through the SIREN synthesizer, scaling each layer by the corresponding modulator output, then applies a tanh and reshapes to a channel-first image batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent
|
Tensor
|
Conditioning latent vector of shape
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
x |
Tensor
|
Output image tensor of shape
|