Other Functions


encoding.functions.scaledL2(X, C, S)[source]

scaledL2 distance

\[sl_{ik} = s_k \|x_i-c_k\|^2\]
  • Input: \(X\in\mathcal{R}^{B\times N\times D}\) \(C\in\mathcal{R}^{K\times D}\) \(S\in \mathcal{R}^K\) (where \(B\) is batch, \(N\) is total number of features, \(K\) is number is codewords, \(D\) is feature dimensions.)
  • Output: \(E\in\mathcal{R}^{B\times N\times K}\)


encoding.functions.upsample(input, size=None, scale_factor=None, mode='nearest')[source]

Multi-GPU version torch.nn.functional.upsample

Upsamples the input to either the given size or the given scale_factor

The algorithm used for upsampling is determined by mode.

Currently temporal, spatial and volumetric upsampling are supported, i.e. expected inputs are 3-D, 4-D or 5-D in shape.

The input dimensions are interpreted in the form: mini-batch x channels x [depth] x [height] x width

The modes available for upsampling are: nearest, linear (3D-only), bilinear (4D-only), trilinear (5D-only)

  • input (Variable) – input
  • size (int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int]) – output spatial size.
  • scale_factor (int) – multiplier for spatial size. Has to be an integer.
  • mode (string) – algorithm used for upsampling: ‘nearest’ | ‘linear’ | ‘bilinear’ | ‘trilinear’. Default: ‘nearest’


encoding.functions.dropout(input, p=0.5, training=False, inplace=True)[source]

Multi-GPU version torch.nn.functional.droupout

The channels to zero-out are randomized on every forward call.

Usually the input comes from Conv2d modules.

As described in the paper Efficient Object Localization Using Convolutional Networks, if adjacent pixels within feature maps are strongly correlated (as is normally the case in early convolution layers) then iid dropout will not regularize the activations and will otherwise just result in an effective learning rate decrease.

In this case, nn.Dropout2d() will help promote independence between feature maps and should be used instead.

  • p (float, optional) – probability of an element to be zeroed.
  • inplace (bool, optional) – If set to True, will do this operation in-place
  • Input: \((N, C, H, W)\)
  • Output: \((N, C, H, W)\) (same shape as input)


encoding.functions.relu(input, inplace=False)[source]

Multi-GPU version torch.nn.functional.relu

Applies the rectified linear unit function element-wise \({ReLU}(x)= max(0, x)\)

Parameters:inplace – can optionally do the operation in-place. Default: False
  • Input: \((N, *)\) where * means, any number of additional dimensions
  • Output: \((N, *)\), same shape as the input


encoding.functions.view_each(x, size)[source]

Multi-GPU version torch.view

Returns a new tensor with the same data but different size. The returned tensor shares the same data and must have the same number of elements, but may have a different size. A tensor must be contiguous to be viewed.

  • input – list of multi-gpu tensors
  • size (torch.Size or int...) – Desired size


encoding.functions.multi_each(a, b)[source]

Multi-GPU version multiplication

\[y[i] = a[i] * b[i]\]


encoding.functions.sum_each(x, y)[source]

Multi-GPU version torch.add

\[y[i] = a[i] + b[i]\]


encoding.functions.cat_each(x1, x2, dim)[source]

Multi-GPU version torch.cat

\[y[i] = torch.cat(a[i], b[i], dim)\]