engine

Indexed Convolution

IndexedConv

class indexedconv.engine.IndexedConv(in_channels, out_channels, indices, bias=True)

Applies a convolution over an input tensor where neighborhood relationships between elements are explicitly provided via an indices tensor.

The output value of the layer with input size \((N, C_{in}, L)\) and output \((N, C_{out}, L)\) can be described as:

\[\begin{array}{ll} out(N_i, C_{out_j}) = bias(C_{out_j}) + \sum_{{c}=0}^{C_{in}-1} \sum_{{i}=0}^{L-1} \sum_{{k}=0}^{K} weight(C_{out_j}, c, k) * input(N_i, c, indices(i, k)) \end{array}\]

where

indices is a L x K tensor, where K is the size of the convolution kernel,
providing the indices of the K neighbors of input element i.
A -1 entry means zero-padding.
Parameters:
  • in_channels (int) – Number of channels in the input tensor

  • out_channels (int) – Number of channels produced by the convolution

  • indices (LongTensor) – index tensor of shape (L x kernel_size), having on each

  • a (row the indices of neighbors of each element of the input a -1 indicates the absence of) –

  • neighbor

  • zero-padding (which is handled as) –

  • bias (bool, optional) – If True, adds a learnable bias to the output. Default: True

Shape:
  • Input: \((N, C_{in}, L)\)

  • Output: \((N, C_{out}, L)\)

Variables:
  • weight (Tensor) – the learnable weights of the module of shape (out_channels, in_channels, kernel_size)

  • bias (Tensor) – the learnable bias of the module of shape (out_channels)

Examples:

>>> indices = (10 * torch.rand(50, 3)).type(torch.LongTensor)
>>> m = nn.IndexedConv(16, 3, indices)
>>> input = torch.randn(20, 16, 50)
>>> output = m(input)

Indexed Pooling

IndexedMaxPool2d

class indexedconv.engine.IndexedMaxPool2d(indices)

Compute the Max Pooling 2d operation on a batch of features of vector images wrt a matrix of indices

Parameters:

indices (LongTensor) – index tensor of shape (L x kernel_size), having on each row the indices of neighbors of each element of the input a -1 indicates the absence of a neighbor, which is handled as zero-padding

Shape:
  • Input: \((N, C, L_{in})\)

  • Output: \((N, C, L_{out})\)

IndexedAveragePool2d

class indexedconv.engine.IndexedAveragePool2d(indices)

Compute the Average Pooling 2d operation on a batch of features of vector images wrt a matrix of indices

Parameters:

indices (LongTensor) – index tensor of shape (L x kernel_size), having on each row the indices of neighbors of each element of the input a -1 indicates the absence of a neighbor, which is handled as zero-padding

Shape:
  • Input: \((N, C, L_{in})\)

  • Output: \((N, C, L_{out})\)