BoxModulationND#

class BoxModulationND(data_dim, max_offset)#

Bases: Module

Fixed box (hard) window applied to implicit convolutional kernels.

Geometry#

The kernel produced by an implicit kernel network has \(K_d\) taps on axis \(d\), centred at tap index \(\lfloor K_d / 2 \rfloor\) (lag zero). With tap offsets \(o_d = i_d - \lfloor K_d / 2 \rfloor\), the mask is

\[m(o) = \prod_{d=0}^{D-1} \mathbb{1}\bigl[\,|o_d| \le \text{max\_offset}\,\bigr]\]

1 = kept, 0 = excluded. Unlike the Gaussian and exponential windows the box is measured in integer taps rather than in normalised grid coordinates, so it is exact at any runtime kernel size and matches a hard crop of the filter at |offset| > max_offset. It has no parameters.

The window is read off x.shape; the grid argument is accepted for interface compatibility with the other masks and is not used.

param data_dim:

Number of spatial axes of the kernel.

param max_offset:

Largest tap offset from the kernel centre that is kept, in taps, on every axis. Must be >= 1; use torch.nn.Identity for no window.

__init__(data_dim, max_offset)#

Initialise the box window; see the class docstring for the arguments.

Parameters:
  • data_dim (int)

  • max_offset (int)

extra_repr()#

Return a short summary string.

Return type:

str

forward(grid, x)#

Zero every kernel tap farther than max_offset from the centre.

Parameters:
  • grid (Tensor) – Coordinate grid [1, *spatial_dims, data_dim]; unused.

  • x (Tensor) – Kernel tensor [B, *spatial_dims, num_channels].

Returns:

x with the taps outside the window set to zero; same shape and dtype as x.

Return type:

torch.Tensor

Raises:

ValueError – If x does not have data_dim spatial axes.

Parameters:
  • data_dim (int)

  • max_offset (int)