nntoolbox.vision.components.kervolution module

class nntoolbox.vision.components.kervolution.GaussianKernel(bandwidth: int = 1, trainable=True)[source]

Bases: torch.nn.modules.module.Module

forward(input: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor)[source]
Parameters
  • input – (batch_size, patch_size, n_patches)

  • weight – (out_channels, in_channels, kernel_height, kernel_width)

Returns

training: bool
class nntoolbox.vision.components.kervolution.Kervolution2D(in_channels, out_channels, kernel, kernel_size, stride=1, padding=0, dilation=1, bias=True, padding_mode='zeros')[source]

Bases: torch.nn.modules.conv.Conv2d

bias: Optional[torch.Tensor]
compute_output_shape(height, width)[source]
dilation: Tuple[int, ]
forward(input)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

groups: int
kernel_size: Tuple[int, ]
out_channels: int
output_padding: Tuple[int, ]
padding: Tuple[int, ]
padding_mode: str
stride: Tuple[int, ]
transposed: bool
weight: torch.Tensor
class nntoolbox.vision.components.kervolution.KervolutionalLayer(in_channels, out_channels, kernel, kernel_size=3, stride=1, padding=0, bias=False, activation=<class 'torch.nn.modules.activation.ReLU'>, normalization=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>)[source]

Bases: torch.nn.modules.container.Sequential

Simple convolutional layer: input -> conv2d -> activation -> norm 2d

training: bool
class nntoolbox.vision.components.kervolution.LinearKernel(cp: float = 1.0, trainable=True)[source]

Bases: torch.nn.modules.module.Module

forward(input: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class nntoolbox.vision.components.kervolution.PolynomialKernel(dp: int = 3, cp: float = 2.0, trainable=True)[source]

Bases: nntoolbox.vision.components.kervolution.LinearKernel

forward(input: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool