Core Modules
Feature extraction modules that process spatio-temporal visual input into learned representations.
SimpleCoreWrapper
The primary convolutional core used in most models. Stacks spatio-temporal separable Conv3D layers with configurable regularization (Laplace, group sparsity, temporal smoothness).
SimpleCoreWrapper
SimpleCoreWrapper(
channels: tuple[int, ...],
temporal_kernel_sizes: tuple[int, ...],
spatial_kernel_sizes: tuple[int, ...],
gamma_input: float,
gamma_temporal: float,
gamma_in_sparse: float,
gamma_hidden: float,
dropout_rate: float = 0.0,
cut_first_n_frames: int = 30,
maxpool_every_n_layers: int | None = None,
downsample_input_kernel_size: tuple[int, int, int]
| None = None,
input_padding: bool
| int
| str
| tuple[int, int, int] = False,
hidden_padding: bool
| int
| str
| tuple[int, int, int] = True,
color_squashing_weights: tuple[float, ...]
| None = None,
convolution_type: str = "custom_separable",
n_neurons_dict: dict[str, int] | None = None,
)
Bases: Core
Source code in openretina/modules/core/base_core.py
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
forward
forward(input_: Tensor) -> Tensor
Source code in openretina/modules/core/base_core.py
161 162 163 164 165 166 167 168 169 170 171 | |
regularizer
regularizer() -> Tensor
Source code in openretina/modules/core/base_core.py
222 223 224 225 226 227 228 229 230 231 232 233 | |
save_weight_visualizations
save_weight_visualizations(
folder_path: str,
file_format: str = "jpg",
state_suffix: str = "",
) -> None
Source code in openretina/modules/core/base_core.py
244 245 246 247 248 249 250 | |
DummyCore
DummyCore
DummyCore(cut_first_n_frames: int | None = None, **kwargs)
Bases: Core
A dummy core that does nothing. Used for readout only models, like the LNP model.
Source code in openretina/modules/core/base_core.py
258 259 260 | |
ConvGRUCore
A recurrent core using convolutional GRU cells for temporal processing.
ConvGRUCore
ConvGRUCore(
channels: tuple[int, ...],
n_neurons_dict: dict[str, int] | None = None,
temporal_kernel_sizes=(21,),
spatial_kernel_sizes=(14,),
gamma_hidden: float = 0.0,
gamma_input: float = 0.0,
gamma_in_sparse: float = 0.0,
gamma_temporal: float = 0.0,
final_nonlinearity: bool = True,
bias: bool = True,
input_padding: bool = False,
hidden_padding: bool = True,
batch_norm: bool = True,
batch_norm_scale: bool = True,
batch_norm_momentum: float = 0.1,
laplace_padding: int | None = 0,
batch_adaptation: bool = False,
use_avg_reg: bool = False,
nonlinearity: str = "ELU",
convolution_type: str = "custom_separable",
use_gru: bool = False,
use_projections: bool = False,
gru_kwargs: dict[str, int | float] | None = None,
**kwargs,
)
Bases: Core3d, Module
Source code in openretina/modules/core/gru_core.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 | |
forward
forward(input_, data_key=None)
Source code in openretina/modules/core/gru_core.py
114 115 116 117 118 119 120 121 122 123 124 125 | |
regularizer
regularizer()
Source code in openretina/modules/core/gru_core.py
270 271 272 273 274 275 276 277 278 279 | |
ResidualAttentionCore
The stock first layer followed by inverted residual depthwise blocks and causal temporal self-attention
(per spatial position, sliding window, learned per-lag bias). The residual blocks follow the DwiseNeuro core of the
Sensorium 2023 winning solution. Train it with
configs/hoefling_2024_core_readout_low_res_residual_attention.yaml, which uses long training chunks and weight EMA.
openretina.callbacks.ema.RampedEMAWeightAveraging uses a decay of min(0.999, (1 + n) / (10 + n)),
where n counts completed EMA updates. The decay reaches 0.999 after roughly 9,000 updates.
To resume training with the raw weights and optimizer state, use a checkpoint saved during fitting.
ResidualAttentionCore
ResidualAttentionCore(
channels: tuple[int, ...],
temporal_kernel_sizes: tuple[int, ...],
spatial_kernel_sizes: tuple[int, ...],
gamma_input: float,
gamma_temporal: float,
gamma_in_sparse: float,
gamma_hidden: float = 0.0,
n_blocks: int = 2,
block_expansion: int = 4,
block_spatial_kernel: int | list[int] = 5,
block_temporal_kernel: int | list[int] = 6,
attn_blocks: int = 1,
attn_heads: int = 2,
attn_window: int = 256,
attn_mlp_ratio: int = 4,
attn_ls_init: float = 0.1,
attn_dropout: float = 0.0,
n_neurons_dict: dict[str, int] | None = None,
**stem_kwargs: Any,
)
Bases: Core
Stock openretina first layer, inverted residual depthwise blocks, and causal temporal attention.
| PARAMETER | DESCRIPTION |
|---|---|
channels
|
(input channels, stem width). The stem width is also the width of the blocks and attention.
TYPE:
|
temporal_kernel_sizes
|
temporal kernel of the stem; only the first entry is used.
TYPE:
|
spatial_kernel_sizes
|
spatial kernel of the stem; only the first entry is used.
TYPE:
|
gamma_input, gamma_temporal, gamma_in_sparse, gamma_hidden
|
stem regularisation, as in
|
n_blocks
|
number of inverted residual blocks.
TYPE:
|
block_expansion
|
channel expansion factor inside the blocks.
TYPE:
|
block_spatial_kernel
|
positive odd depthwise spatial kernel size, shared or one value per block.
TYPE:
|
block_temporal_kernel
|
depthwise temporal kernel size, an int or one value per block.
TYPE:
|
attn_blocks
|
number of causal temporal attention blocks after the residual blocks (0 disables attention).
TYPE:
|
attn_heads
|
attention heads; must divide the stem width.
TYPE:
|
attn_window
|
how many past frames (including the current one) each frame may attend to.
TYPE:
|
attn_mlp_ratio
|
hidden width of the attention MLP relative to the stem width.
TYPE:
|
attn_ls_init
|
initial LayerScale value of both attention-block residual branches.
TYPE:
|
attn_dropout
|
dropout on the attention weights during training.
TYPE:
|
n_neurons_dict
|
passed by
TYPE:
|
**stem_kwargs
|
further keyword arguments for the stem
TYPE:
|
Source code in openretina/modules/core/residual_attention_core.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
forward
forward(x: Tensor, data_key: str | None = None) -> Tensor
Source code in openretina/modules/core/residual_attention_core.py
305 306 | |
regularizer
regularizer() -> Tensor
Source code in openretina/modules/core/residual_attention_core.py
308 309 | |
CausalTemporalAttention
CausalTemporalAttention(
channels: int,
heads: int = 2,
window: int = 256,
mlp_ratio: int = 4,
ls_init: float = 0.1,
dropout: float = 0.0,
)
Bases: Module
Pre-norm transformer block that attends along time only, separately at every spatial position.
Tokens are the C-dimensional feature vectors at each (position, frame). Frame t attends to frames
t - window + 1 .. t (causal sliding window). Positions are encoded only by a learned per-head bias for each lag
(relative positions, no absolute positions), so training and test sequences may differ in length. Weights are
shared across spatial positions. Both residual branches (attention and MLP) are gated by LayerScale,
initialised at ls_init.
Source code in openretina/modules/core/residual_attention_core.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
attn_bias
attn_bias(
t: int,
device: device,
dtype: dtype,
*,
history: int = 0,
) -> Tensor
Bias for t queries and their keys, including history keys preceding the first query.
Source code in openretina/modules/core/residual_attention_core.py
177 178 179 180 181 182 183 | |