omnibias.keras.blocks.conv
Keras 3 operator layers and activation paths implemented with keras.ops for TensorFlow, JAX, or Torch.
import omnibias.keras.blocks.convModule contract & mathematical conventions
Operator-typed convolution layers: cmbConv1D, cmbConv2D.
Each is a standard keras.layers.Conv* (channels-last) followed by an
OperatorBlock applied per output channel. Because Keras conv
layers are channels-last by default, the operator block (which acts on
the last axis) applies directly with no permutation. Mirrors
omnibias.torch.blocks.conv.
Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.
AnalyticGaussianConv1D
omnibias.keras.AnalyticGaussianConv1DSource ↗class AnalyticGaussianConv1D(_AnalyticGaussianConvBase)Depthwise 1-D convolution with an exact, continuous-scale Gaussian kernel.
Keras twin of omnibias.torch.blocks.conv.AnalyticGaussianConv1d. The
per-channel taps are built in closed form from the learnable scale sigma
via analytic_gaussian_taps, so the layer is anti-aliased, sampling-free
and differentiable end-to-end in sigma. derivative_order=0 is a Gaussian
blur; 1 a derivative-of-Gaussian; 2 a 1-D Laplacian-of-Gaussian.
Layout: channels-last (B, L, channels) -> (B, L_out, channels).
Parameters
| Name | Type & default | Contract |
|---|---|---|
channelspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | intRequired | See the operation contract and implementation below. |
derivative_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
sigma_initkeyword-only | floatDefault: 1.0 | See the operation contract and implementation below. |
learnable_sigmakeyword-only | boolDefault: True | See the operation contract and implementation below. |
strideskeyword-only | intDefault: 1 | See the operation contract and implementation below. |
paddingkeyword-only | strDefault: 'same' | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Executed regression · conv1d matches manual correlation
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv1d_matches_manual_correlation() -> None:
rng = np.random.default_rng(0)
c, length, k = 3, 24, 7
layer = AnalyticGaussianConv1D(c, k, sigma_init=1.2)
x = rng.standard_normal((2, length, c))
out = _np(layer(_t(x)))
taps = _np(analytic_gaussian_taps(k, layer.sigma, 0))
np.testing.assert_allclose(out, _corr1d_same(x, taps), rtol=1e-12, atol=1e-12)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv1d_matches_manual_correlation" -qRegression example · trainable scale weight
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_trainable_scale_weight() -> None:
learn = AnalyticGaussianConv1D(2, 7, sigma_init=1.0, learnable_sigma=True)
learn.build((None, 16, 2))
assert any(w.name == "sigma" for w in learn.trainable_weights)
frozen = AnalyticGaussianConv1D(2, 7, sigma_init=1.0, learnable_sigma=False)
frozen.build((None, 16, 2))
assert all(w.name != "sigma" for w in frozen.trainable_weights)python -m pytest packages/omnibias-keras/tests/test_analytic_gaussian_conv.py -k test_trainable_scale_weight -qFields & methods
__init__method
__init__(self, channels: int, kernel_size: int, *, derivative_order: int=0, sigma_init: float=1.0, learnable_sigma: bool=True, strides: int=1, padding: str='same', **kwargs: Any) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
channelspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | intRequired | See the operation contract and implementation below. |
derivative_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
sigma_initkeyword-only | floatDefault: 1.0 | See the operation contract and implementation below. |
learnable_sigmakeyword-only | boolDefault: True | See the operation contract and implementation below. |
strideskeyword-only | intDefault: 1 | See the operation contract and implementation below. |
paddingkeyword-only | strDefault: 'same' | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Returns: None
Executed regression · conv1d matches manual correlation
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv1d_matches_manual_correlation() -> None:
rng = np.random.default_rng(0)
c, length, k = 3, 24, 7
layer = AnalyticGaussianConv1D(c, k, sigma_init=1.2)
x = rng.standard_normal((2, length, c))
out = _np(layer(_t(x)))
taps = _np(analytic_gaussian_taps(k, layer.sigma, 0))
np.testing.assert_allclose(out, _corr1d_same(x, taps), rtol=1e-12, atol=1e-12)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv1d_matches_manual_correlation" -qMethod implementation
def __init__(
self,
channels: int,
kernel_size: int,
*,
derivative_order: int = 0,
sigma_init: float = 1.0,
learnable_sigma: bool = True,
strides: int = 1,
padding: str = "same",
**kwargs: Any,
) -> None:
super().__init__(channels, sigma_init, learnable_sigma, **kwargs)
self.kernel_size = kernel_size
self.derivative_order = derivative_order
self.strides = strides
self.padding = paddingcallmethod
call(self, x: Any) -> AnySee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | AnyRequired | See the operation contract and implementation below. |
Returns: Any
Executed regression · conv1d matches manual correlation
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv1d_matches_manual_correlation() -> None:
rng = np.random.default_rng(0)
c, length, k = 3, 24, 7
layer = AnalyticGaussianConv1D(c, k, sigma_init=1.2)
x = rng.standard_normal((2, length, c))
out = _np(layer(_t(x)))
taps = _np(analytic_gaussian_taps(k, layer.sigma, 0))
np.testing.assert_allclose(out, _corr1d_same(x, taps), rtol=1e-12, atol=1e-12)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv1d_matches_manual_correlation" -qMethod implementation
def call(self, x: Any) -> Any:
taps = analytic_gaussian_taps(self.kernel_size, self._safe_sigma(), self.derivative_order)
kernel = ops.cast(ops.expand_dims(ops.transpose(taps), -1), x.dtype) # (K, C, 1)
return ops.depthwise_conv(x, kernel, strides=self.strides, padding=self.padding)kernel_sizeattribute
kernel_size: int = kernel_sizePublic instance attribute assigned by __init__. The source assignment is kernel_size = kernel_size; it describes instance state, not a literal constructor default.
derivative_orderattribute
derivative_order: int = derivative_orderPublic instance attribute assigned by __init__. The source assignment is derivative_order = derivative_order; it describes instance state, not a literal constructor default.
stridesattribute
strides: int = stridesPublic instance attribute assigned by __init__. The source assignment is strides = strides; it describes instance state, not a literal constructor default.
paddingattribute
padding: str = paddingPublic instance attribute assigned by __init__. The source assignment is padding = padding; it describes instance state, not a literal constructor default.
Read the implementation
class AnalyticGaussianConv1D(_AnalyticGaussianConvBase):
r"""Depthwise 1-D convolution with an exact, continuous-scale Gaussian kernel.
Keras twin of :class:`omnibias.torch.blocks.conv.AnalyticGaussianConv1d`. The
per-channel taps are built in closed form from the learnable scale ``sigma``
via :func:`analytic_gaussian_taps`, so the layer is anti-aliased, sampling-free
and differentiable end-to-end in ``sigma``. ``derivative_order=0`` is a Gaussian
blur; ``1`` a derivative-of-Gaussian; ``2`` a 1-D Laplacian-of-Gaussian.
Layout: channels-last ``(B, L, channels) -> (B, L_out, channels)``.
"""
def __init__(
self,
channels: int,
kernel_size: int,
*,
derivative_order: int = 0,
sigma_init: float = 1.0,
learnable_sigma: bool = True,
strides: int = 1,
padding: str = "same",
**kwargs: Any,
) -> None:
super().__init__(channels, sigma_init, learnable_sigma, **kwargs)
self.kernel_size = kernel_size
self.derivative_order = derivative_order
self.strides = strides
self.padding = padding
def call(self, x: Any) -> Any:
taps = analytic_gaussian_taps(self.kernel_size, self._safe_sigma(), self.derivative_order)
kernel = ops.cast(ops.expand_dims(ops.transpose(taps), -1), x.dtype) # (K, C, 1)
return ops.depthwise_conv(x, kernel, strides=self.strides, padding=self.padding)Other public import paths
omnibias.keras.AnalyticGaussianConv1Domnibias.keras.blocks.AnalyticGaussianConv1Domnibias.keras.blocks.conv.AnalyticGaussianConv1D
AnalyticGaussianConv2D
omnibias.keras.AnalyticGaussianConv2DSource ↗class AnalyticGaussianConv2D(_AnalyticGaussianConvBase)Depthwise 2-D separable analytic Gaussian / derivative-of-Gaussian conv.
Keras twin of omnibias.torch.blocks.conv.AnalyticGaussianConv2d. The
isotropic Gaussian is separable, so the 2-D kernel is the outer product of two
1-D analytic_gaussian_taps profiles. derivative_order is (n_y, n_x);
a Laplacian-of-Gaussian is the sum of a (2, 0) and a (0, 2) layer.
Layout: channels-last (B, H, W, channels) -> (B, H_out, W_out, channels).
Parameters
| Name | Type & default | Contract |
|---|---|---|
channelspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | int | tuple[int, int]Required | See the operation contract and implementation below. |
derivative_orderkeyword-only | int | tuple[int, int]Default: 0 | See the operation contract and implementation below. |
sigma_initkeyword-only | floatDefault: 1.0 | See the operation contract and implementation below. |
learnable_sigmakeyword-only | boolDefault: True | See the operation contract and implementation below. |
strideskeyword-only | int | tuple[int, int]Default: 1 | See the operation contract and implementation below. |
paddingkeyword-only | strDefault: 'same' | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Executed regression · conv2d runs and is separable
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv2d_runs_and_is_separable() -> None:
rng = np.random.default_rng(3)
c, k = 3, 5
layer = AnalyticGaussianConv2D(c, k, derivative_order=(0, 1), sigma_init=1.1)
x = rng.standard_normal((2, 10, 11, c))
out = _np(layer(_t(x)))
assert out.shape == (2, 10, 11, c)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv2d_runs_and_is_separable" -qRegression example · conv1d matches manual correlation
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv1d_matches_manual_correlation() -> None:
rng = np.random.default_rng(0)
c, length, k = 3, 24, 7
layer = AnalyticGaussianConv1D(c, k, sigma_init=1.2)
x = rng.standard_normal((2, length, c))
out = _np(layer(_t(x)))
taps = _np(analytic_gaussian_taps(k, layer.sigma, 0))
np.testing.assert_allclose(out, _corr1d_same(x, taps), rtol=1e-12, atol=1e-12)python -m pytest packages/omnibias-keras/tests/test_analytic_gaussian_conv.py -k test_conv1d_matches_manual_correlation -qFields & methods
__init__method
__init__(self, channels: int, kernel_size: int | tuple[int, int], *, derivative_order: int | tuple[int, int]=0, sigma_init: float=1.0, learnable_sigma: bool=True, strides: int | tuple[int, int]=1, padding: str='same', **kwargs: Any) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
channelspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | int | tuple[int, int]Required | See the operation contract and implementation below. |
derivative_orderkeyword-only | int | tuple[int, int]Default: 0 | See the operation contract and implementation below. |
sigma_initkeyword-only | floatDefault: 1.0 | See the operation contract and implementation below. |
learnable_sigmakeyword-only | boolDefault: True | See the operation contract and implementation below. |
strideskeyword-only | int | tuple[int, int]Default: 1 | See the operation contract and implementation below. |
paddingkeyword-only | strDefault: 'same' | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Returns: None
Executed regression · conv2d runs and is separable
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv2d_runs_and_is_separable() -> None:
rng = np.random.default_rng(3)
c, k = 3, 5
layer = AnalyticGaussianConv2D(c, k, derivative_order=(0, 1), sigma_init=1.1)
x = rng.standard_normal((2, 10, 11, c))
out = _np(layer(_t(x)))
assert out.shape == (2, 10, 11, c)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv2d_runs_and_is_separable" -qMethod implementation
def __init__(
self,
channels: int,
kernel_size: int | tuple[int, int],
*,
derivative_order: int | tuple[int, int] = 0,
sigma_init: float = 1.0,
learnable_sigma: bool = True,
strides: int | tuple[int, int] = 1,
padding: str = "same",
**kwargs: Any,
) -> None:
super().__init__(channels, sigma_init, learnable_sigma, **kwargs)
kh, kw = (kernel_size, kernel_size) if isinstance(kernel_size, int) else kernel_size
ny, nx = (
(derivative_order, derivative_order)
if isinstance(derivative_order, int)
else derivative_order
)
self.kernel_size = (kh, kw)
self.derivative_order = (ny, nx)
self.strides = strides
self.padding = paddingcallmethod
call(self, x: Any) -> AnySee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | AnyRequired | See the operation contract and implementation below. |
Returns: Any
Executed regression · conv2d runs and is separable
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv2d_runs_and_is_separable() -> None:
rng = np.random.default_rng(3)
c, k = 3, 5
layer = AnalyticGaussianConv2D(c, k, derivative_order=(0, 1), sigma_init=1.1)
x = rng.standard_normal((2, 10, 11, c))
out = _np(layer(_t(x)))
assert out.shape == (2, 10, 11, c)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv2d_runs_and_is_separable" -qMethod implementation
def call(self, x: Any) -> Any:
sigma = self._safe_sigma()
kh, kw = self.kernel_size
ny, nx = self.derivative_order
ty = analytic_gaussian_taps(kh, sigma, ny) # (C, Kh)
tx = analytic_gaussian_taps(kw, sigma, nx) # (C, Kw)
kernel2d = ops.expand_dims(ty, -1) * ops.expand_dims(tx, -2) # (C, Kh, Kw)
kernel = ops.expand_dims(ops.transpose(kernel2d, (1, 2, 0)), -1) # (Kh, Kw, C, 1)
return ops.depthwise_conv(x, ops.cast(kernel, x.dtype), strides=self.strides, padding=self.padding)kernel_sizeattribute
kernel_size = (kh, kw)Public instance attribute assigned by __init__. The source assignment is kernel_size = (kh, kw); it describes instance state, not a literal constructor default.
derivative_orderattribute
derivative_order = (ny, nx)Public instance attribute assigned by __init__. The source assignment is derivative_order = (ny, nx); it describes instance state, not a literal constructor default.
stridesattribute
strides: int | tuple[int, int] = stridesPublic instance attribute assigned by __init__. The source assignment is strides = strides; it describes instance state, not a literal constructor default.
paddingattribute
padding: str = paddingPublic instance attribute assigned by __init__. The source assignment is padding = padding; it describes instance state, not a literal constructor default.
Read the implementation
class AnalyticGaussianConv2D(_AnalyticGaussianConvBase):
r"""Depthwise 2-D separable analytic Gaussian / derivative-of-Gaussian conv.
Keras twin of :class:`omnibias.torch.blocks.conv.AnalyticGaussianConv2d`. The
isotropic Gaussian is separable, so the 2-D kernel is the outer product of two
1-D :func:`analytic_gaussian_taps` profiles. ``derivative_order`` is ``(n_y, n_x)``;
a Laplacian-of-Gaussian is the sum of a ``(2, 0)`` and a ``(0, 2)`` layer.
Layout: channels-last ``(B, H, W, channels) -> (B, H_out, W_out, channels)``.
"""
def __init__(
self,
channels: int,
kernel_size: int | tuple[int, int],
*,
derivative_order: int | tuple[int, int] = 0,
sigma_init: float = 1.0,
learnable_sigma: bool = True,
strides: int | tuple[int, int] = 1,
padding: str = "same",
**kwargs: Any,
) -> None:
super().__init__(channels, sigma_init, learnable_sigma, **kwargs)
kh, kw = (kernel_size, kernel_size) if isinstance(kernel_size, int) else kernel_size
ny, nx = (
(derivative_order, derivative_order)
if isinstance(derivative_order, int)
else derivative_order
)
self.kernel_size = (kh, kw)
self.derivative_order = (ny, nx)
self.strides = strides
self.padding = padding
def call(self, x: Any) -> Any:
sigma = self._safe_sigma()
kh, kw = self.kernel_size
ny, nx = self.derivative_order
ty = analytic_gaussian_taps(kh, sigma, ny) # (C, Kh)
tx = analytic_gaussian_taps(kw, sigma, nx) # (C, Kw)
kernel2d = ops.expand_dims(ty, -1) * ops.expand_dims(tx, -2) # (C, Kh, Kw)
kernel = ops.expand_dims(ops.transpose(kernel2d, (1, 2, 0)), -1) # (Kh, Kw, C, 1)
return ops.depthwise_conv(x, ops.cast(kernel, x.dtype), strides=self.strides, padding=self.padding)Other public import paths
omnibias.keras.AnalyticGaussianConv2Domnibias.keras.blocks.AnalyticGaussianConv2Domnibias.keras.blocks.conv.AnalyticGaussianConv2D
analytic_gaussian_taps
omnibias.keras.analytic_gaussian_tapsSource ↗analytic_gaussian_taps(kernel_size: int, sigma: Any, order: int=0) -> AnyExact cell-integrated Gaussian / derivative-of-Gaussian kernel taps.
Keras twin of omnibias.torch.blocks.conv.analytic_gaussian_taps;
bit-identical closed form. Returns taps of shape (*sigma.shape, kernel_size)
for a continuous-scale Gaussian of standard deviation sigma (pixel units).
Tap j is the *integral* of the (order-th derivative of the) unit-area
Gaussian over the cell [j - 1/2, j + 1/2] (exact, anti-aliased area
sampling). order=0 uses the erf antiderivative; order>=1 uses the
closed-form Gaussian derivative tower (gaussian_nth_derivative).
Differentiable in sigma.
Parameters
| Name | Type & default | Contract |
|---|---|---|
kernel_sizepositional-or-keyword | intRequired | See the operation contract and implementation below. |
sigmapositional-or-keyword | AnyRequired | See the operation contract and implementation below. |
orderpositional-or-keyword | intDefault: 0 | See the operation contract and implementation below. |
AnyExplicit validation & failure cases
- When
kernel_size < 1 or kernel_size % 2 == 0, raisesValueError(f'kernel_size must be a positive odd integer, got {kernel_size}'). - When
order < 0, raisesValueError(f'order must be >= 0, got {order}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · conv2d runs and is separable
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_conv2d_runs_and_is_separable() -> None:
rng = np.random.default_rng(3)
c, k = 3, 5
layer = AnalyticGaussianConv2D(c, k, derivative_order=(0, 1), sigma_init=1.1)
x = rng.standard_normal((2, 10, 11, c))
out = _np(layer(_t(x)))
assert out.shape == (2, 10, 11, c)python -m pytest "packages/omnibias-keras/tests/test_analytic_gaussian_conv.py::test_conv2d_runs_and_is_separable" -qRegression example · taps bit parity with torch
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_taps_bit_parity_with_torch(order: int) -> None:
sigma = np.array([0.7, 1.3, 2.1])
keras_taps = _np(analytic_gaussian_taps(9, _t(sigma), order))
t_taps = torch_taps(9, torch.tensor(sigma, dtype=torch.float64), order).numpy()
np.testing.assert_allclose(keras_taps, t_taps, rtol=1e-12, atol=1e-12)python -m pytest packages/omnibias-keras/tests/test_analytic_gaussian_conv.py -k test_taps_bit_parity_with_torch -qRead the implementation
def analytic_gaussian_taps(kernel_size: int, sigma: Any, order: int = 0) -> Any:
r"""Exact cell-integrated Gaussian / derivative-of-Gaussian kernel taps.
Keras twin of :func:`omnibias.torch.blocks.conv.analytic_gaussian_taps`;
bit-identical closed form. Returns taps of shape ``(*sigma.shape, kernel_size)``
for a continuous-scale Gaussian of standard deviation ``sigma`` (pixel units).
Tap ``j`` is the *integral* of the (``order``-th derivative of the) unit-area
Gaussian over the cell ``[j - 1/2, j + 1/2]`` (exact, anti-aliased area
sampling). ``order=0`` uses the ``erf`` antiderivative; ``order>=1`` uses the
closed-form Gaussian derivative tower (:func:`gaussian_nth_derivative`).
Differentiable in ``sigma``.
"""
if kernel_size < 1 or kernel_size % 2 == 0:
raise ValueError(f"kernel_size must be a positive odd integer, got {kernel_size}")
if order < 0:
raise ValueError(f"order must be >= 0, got {order}")
half = kernel_size // 2
offsets = ops.cast(ops.arange(-half, half + 1), sigma.dtype)
sig = ops.expand_dims(sigma, -1)
a = (offsets - _HALF) / sig
b = (offsets + _HALF) / sig
if order == 0:
return _HALF * (ops.erf(b / _SQRT_2) - ops.erf(a / _SQRT_2))
gm = gaussian_nth_derivative(b, order - 1) - gaussian_nth_derivative(a, order - 1)
return gm * (_INV_SQRT_2PI / ops.power(sig, order))Other public import paths
omnibias.keras.analytic_gaussian_tapsomnibias.keras.blocks.analytic_gaussian_tapsomnibias.keras.blocks.conv.analytic_gaussian_taps
cmbConv1D
omnibias.keras.cmbConv1DSource ↗class cmbConv1D(layers.Layer)keras.layers.Conv1D + per-channel OperatorBlock.
Layout: input (B, L, in_channels) -> output (B, L_out, filters).
Parameters
| Name | Type & default | Contract |
|---|---|---|
filterspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | intRequired | See the operation contract and implementation below. |
oppositional-or-keyword | OpNameDefault: 'identity' | See the operation contract and implementation below. |
basepositional-or-keyword | str | ActivationSpec[Any]Default: 'tanh' | See the operation contract and implementation below. |
stridespositional-or-keyword | intDefault: 1 | See the operation contract and implementation below. |
paddingpositional-or-keyword | strDefault: 'valid' | See the operation contract and implementation below. |
dilation_ratepositional-or-keyword | intDefault: 1 | See the operation contract and implementation below. |
use_biaspositional-or-keyword | boolDefault: True | See the operation contract and implementation below. |
block_kwargspositional-or-keyword | dict[str, Any] | NoneDefault: None | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Executed regression · cmbconv1d shape
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv1d_shape() -> None:
x = np.random.default_rng(6).normal(size=(4, 10, 3))
layer = cmbConv1D(filters=5, kernel_size=3, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 5python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbconv1d_shape" -qFields & methods
__init__method
__init__(self, filters: int, kernel_size: int, op: OpName='identity', base: str | ActivationSpec[Any]='tanh', strides: int=1, padding: str='valid', dilation_rate: int=1, use_bias: bool=True, block_kwargs: dict[str, Any] | None=None, **kwargs: Any) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
filterspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | intRequired | See the operation contract and implementation below. |
oppositional-or-keyword | OpNameDefault: 'identity' | See the operation contract and implementation below. |
basepositional-or-keyword | str | ActivationSpec[Any]Default: 'tanh' | See the operation contract and implementation below. |
stridespositional-or-keyword | intDefault: 1 | See the operation contract and implementation below. |
paddingpositional-or-keyword | strDefault: 'valid' | See the operation contract and implementation below. |
dilation_ratepositional-or-keyword | intDefault: 1 | See the operation contract and implementation below. |
use_biaspositional-or-keyword | boolDefault: True | See the operation contract and implementation below. |
block_kwargspositional-or-keyword | dict[str, Any] | NoneDefault: None | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Returns: None
Executed regression · cmbconv1d shape
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv1d_shape() -> None:
x = np.random.default_rng(6).normal(size=(4, 10, 3))
layer = cmbConv1D(filters=5, kernel_size=3, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 5python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbconv1d_shape" -qMethod implementation
def __init__(
self,
filters: int,
kernel_size: int,
op: OpName = "identity",
base: str | ActivationSpec[Any] = "tanh",
strides: int = 1,
padding: str = "valid",
dilation_rate: int = 1,
use_bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.filters = filters
self.kernel_size = kernel_size
self._op = op
self._base_name = base if isinstance(base, str) else base.name
self._block_kwargs = block_kwargs or {}
self.conv = layers.Conv1D(
filters,
kernel_size,
strides=strides,
padding=padding,
dilation_rate=dilation_rate,
use_bias=use_bias,
)
self.block = OperatorBlock(
op=op, base=base, channels=filters, **self._block_kwargs
)callmethod
call(self, x: Any) -> AnySee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | AnyRequired | See the operation contract and implementation below. |
Returns: Any
Executed regression · cmbconv1d shape
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv1d_shape() -> None:
x = np.random.default_rng(6).normal(size=(4, 10, 3))
layer = cmbConv1D(filters=5, kernel_size=3, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 5python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbconv1d_shape" -qMethod implementation
def call(self, x: Any) -> Any:
return self.block(self.conv(x))get_configmethod
get_config(self) -> dict[str, Any]See the class contract above and the exact method implementation below.
Returns: dict[str, Any]
Method implementation
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update(
{
"filters": self.filters,
"kernel_size": self.kernel_size,
"op": self._op,
"base": self._base_name,
"block_kwargs": self._block_kwargs,
}
)
return configfiltersattribute
filters: int = filtersPublic instance attribute assigned by __init__. The source assignment is filters = filters; it describes instance state, not a literal constructor default.
kernel_sizeattribute
kernel_size: int = kernel_sizePublic instance attribute assigned by __init__. The source assignment is kernel_size = kernel_size; it describes instance state, not a literal constructor default.
convattribute
conv = layers.Conv1D(filters, kernel_size, strides=strides, padding=padding, dilation_rate=dilation_rate, use_bias=use_bias)Public instance attribute assigned by __init__. The source assignment is conv = layers.Conv1D(filters, kernel_size, strides=strides, padding=padding, dilation_rate=dilation_rate, use_bias=use_bias); it describes instance state, not a literal constructor default.
blockattribute
block = OperatorBlock(op=op, base=base, channels=filters, **self._block_kwargs)Public instance attribute assigned by __init__. The source assignment is block = OperatorBlock(op=op, base=base, channels=filters, **self._block_kwargs); it describes instance state, not a literal constructor default.
Read the implementation
class cmbConv1D(layers.Layer):
"""``keras.layers.Conv1D`` + per-channel :class:`OperatorBlock`.
Layout: input ``(B, L, in_channels)`` -> output ``(B, L_out, filters)``.
"""
def __init__(
self,
filters: int,
kernel_size: int,
op: OpName = "identity",
base: str | ActivationSpec[Any] = "tanh",
strides: int = 1,
padding: str = "valid",
dilation_rate: int = 1,
use_bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.filters = filters
self.kernel_size = kernel_size
self._op = op
self._base_name = base if isinstance(base, str) else base.name
self._block_kwargs = block_kwargs or {}
self.conv = layers.Conv1D(
filters,
kernel_size,
strides=strides,
padding=padding,
dilation_rate=dilation_rate,
use_bias=use_bias,
)
self.block = OperatorBlock(
op=op, base=base, channels=filters, **self._block_kwargs
)
def call(self, x: Any) -> Any:
return self.block(self.conv(x))
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update(
{
"filters": self.filters,
"kernel_size": self.kernel_size,
"op": self._op,
"base": self._base_name,
"block_kwargs": self._block_kwargs,
}
)
return configOther public import paths
omnibias.keras.cmbConv1Domnibias.keras.blocks.cmbConv1Domnibias.keras.blocks.conv.cmbConv1D
cmbConv2D
omnibias.keras.cmbConv2DSource ↗class cmbConv2D(layers.Layer)keras.layers.Conv2D + per-channel OperatorBlock.
Layout: input (B, H, W, in_channels) -> output (B, H_out, W_out, filters).
Parameters
| Name | Type & default | Contract |
|---|---|---|
filterspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | int | tuple[int, int]Required | See the operation contract and implementation below. |
oppositional-or-keyword | OpNameDefault: 'identity' | See the operation contract and implementation below. |
basepositional-or-keyword | str | ActivationSpec[Any]Default: 'gaussian' | See the operation contract and implementation below. |
stridespositional-or-keyword | int | tuple[int, int]Default: 1 | See the operation contract and implementation below. |
paddingpositional-or-keyword | strDefault: 'valid' | See the operation contract and implementation below. |
dilation_ratepositional-or-keyword | int | tuple[int, int]Default: 1 | See the operation contract and implementation below. |
use_biaspositional-or-keyword | boolDefault: True | See the operation contract and implementation below. |
block_kwargspositional-or-keyword | dict[str, Any] | NoneDefault: None | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Executed regression · cmbconv2d shape
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv2d_shape() -> None:
x = np.random.default_rng(7).normal(size=(4, 8, 8, 2))
layer = cmbConv2D(filters=3, kernel_size=3, op="laplacian", base="gaussian")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 3python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbconv2d_shape" -qRegression example · cmbconv1d shape
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv1d_shape() -> None:
x = np.random.default_rng(6).normal(size=(4, 10, 3))
layer = cmbConv1D(filters=5, kernel_size=3, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 5python -m pytest packages/omnibias-keras/tests/test_blocks.py -k test_cmbconv1d_shape -qFields & methods
__init__method
__init__(self, filters: int, kernel_size: int | tuple[int, int], op: OpName='identity', base: str | ActivationSpec[Any]='gaussian', strides: int | tuple[int, int]=1, padding: str='valid', dilation_rate: int | tuple[int, int]=1, use_bias: bool=True, block_kwargs: dict[str, Any] | None=None, **kwargs: Any) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
filterspositional-or-keyword | intRequired | See the operation contract and implementation below. |
kernel_sizepositional-or-keyword | int | tuple[int, int]Required | See the operation contract and implementation below. |
oppositional-or-keyword | OpNameDefault: 'identity' | See the operation contract and implementation below. |
basepositional-or-keyword | str | ActivationSpec[Any]Default: 'gaussian' | See the operation contract and implementation below. |
stridespositional-or-keyword | int | tuple[int, int]Default: 1 | See the operation contract and implementation below. |
paddingpositional-or-keyword | strDefault: 'valid' | See the operation contract and implementation below. |
dilation_ratepositional-or-keyword | int | tuple[int, int]Default: 1 | See the operation contract and implementation below. |
use_biaspositional-or-keyword | boolDefault: True | See the operation contract and implementation below. |
block_kwargspositional-or-keyword | dict[str, Any] | NoneDefault: None | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Returns: None
Executed regression · cmbconv2d shape
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv2d_shape() -> None:
x = np.random.default_rng(7).normal(size=(4, 8, 8, 2))
layer = cmbConv2D(filters=3, kernel_size=3, op="laplacian", base="gaussian")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 3python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbconv2d_shape" -qMethod implementation
def __init__(
self,
filters: int,
kernel_size: int | tuple[int, int],
op: OpName = "identity",
base: str | ActivationSpec[Any] = "gaussian",
strides: int | tuple[int, int] = 1,
padding: str = "valid",
dilation_rate: int | tuple[int, int] = 1,
use_bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.filters = filters
self.kernel_size = kernel_size
self._op = op
self._base_name = base if isinstance(base, str) else base.name
self._block_kwargs = block_kwargs or {}
self.conv = layers.Conv2D(
filters,
kernel_size,
strides=strides,
padding=padding,
dilation_rate=dilation_rate,
use_bias=use_bias,
)
self.block = OperatorBlock(
op=op, base=base, channels=filters, **self._block_kwargs
)callmethod
call(self, x: Any) -> AnySee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | AnyRequired | See the operation contract and implementation below. |
Returns: Any
Executed regression · cmbconv2d shape
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cmbconv2d_shape() -> None:
x = np.random.default_rng(7).normal(size=(4, 8, 8, 2))
layer = cmbConv2D(filters=3, kernel_size=3, op="laplacian", base="gaussian")
out = _np(layer(_t(x)))
assert out.shape[0] == 4 and out.shape[-1] == 3python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbconv2d_shape" -qMethod implementation
def call(self, x: Any) -> Any:
return self.block(self.conv(x))get_configmethod
get_config(self) -> dict[str, Any]See the class contract above and the exact method implementation below.
Returns: dict[str, Any]
Method implementation
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update(
{
"filters": self.filters,
"kernel_size": self.kernel_size,
"op": self._op,
"base": self._base_name,
"block_kwargs": self._block_kwargs,
}
)
return configfiltersattribute
filters: int = filtersPublic instance attribute assigned by __init__. The source assignment is filters = filters; it describes instance state, not a literal constructor default.
kernel_sizeattribute
kernel_size: int | tuple[int, int] = kernel_sizePublic instance attribute assigned by __init__. The source assignment is kernel_size = kernel_size; it describes instance state, not a literal constructor default.
convattribute
conv = layers.Conv2D(filters, kernel_size, strides=strides, padding=padding, dilation_rate=dilation_rate, use_bias=use_bias)Public instance attribute assigned by __init__. The source assignment is conv = layers.Conv2D(filters, kernel_size, strides=strides, padding=padding, dilation_rate=dilation_rate, use_bias=use_bias); it describes instance state, not a literal constructor default.
blockattribute
block = OperatorBlock(op=op, base=base, channels=filters, **self._block_kwargs)Public instance attribute assigned by __init__. The source assignment is block = OperatorBlock(op=op, base=base, channels=filters, **self._block_kwargs); it describes instance state, not a literal constructor default.
Read the implementation
class cmbConv2D(layers.Layer):
"""``keras.layers.Conv2D`` + per-channel :class:`OperatorBlock`.
Layout: input ``(B, H, W, in_channels)`` -> output ``(B, H_out, W_out, filters)``.
"""
def __init__(
self,
filters: int,
kernel_size: int | tuple[int, int],
op: OpName = "identity",
base: str | ActivationSpec[Any] = "gaussian",
strides: int | tuple[int, int] = 1,
padding: str = "valid",
dilation_rate: int | tuple[int, int] = 1,
use_bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.filters = filters
self.kernel_size = kernel_size
self._op = op
self._base_name = base if isinstance(base, str) else base.name
self._block_kwargs = block_kwargs or {}
self.conv = layers.Conv2D(
filters,
kernel_size,
strides=strides,
padding=padding,
dilation_rate=dilation_rate,
use_bias=use_bias,
)
self.block = OperatorBlock(
op=op, base=base, channels=filters, **self._block_kwargs
)
def call(self, x: Any) -> Any:
return self.block(self.conv(x))
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update(
{
"filters": self.filters,
"kernel_size": self.kernel_size,
"op": self._op,
"base": self._base_name,
"block_kwargs": self._block_kwargs,
}
)
return configOther public import paths
omnibias.keras.cmbConv2Domnibias.keras.blocks.cmbConv2Domnibias.keras.blocks.conv.cmbConv2D