Convolution

Convolution  // A batched convolution operation

Description

Long description

Inputs

Name

Element Type

Shape

image_batch

Any

(N, C_in, d_1, ..., d_n)

filters

Same as image_batch

(N, C_in, df_1, ..., df_n)

Attributes

Name

Type

Notes

window_movement_strides

Strides[n]

How far to slide the window along each axis at each step

window_dilation_strides

Strides[n]

Per-axis dilation to apply to the filters

padding_below

Shape[n]

How many padding elements to add below the 0-coordinate on each axis

padding_above

Shape[n]

How many padding elements to add above the max-coordinate on each axis

image_dilation_strides

Strides[n]

Per-axis dilation to apply to the image batch

Outputs

Name

Element Type

Shape

features_out

Same as image_batch

(N, C_in, d_1 - df_1 + 1, ..., d_n - df_n + 1)

It must be the case that after dilation and padding are applied, the filter fits within the image.

Mathematical Definition

Padding

Let \(p\) (the padding below) and \(q\) (the padding above) be a sequence of \(n\) integers, and \(T\) be a tensor of shape \((d_1,\dots,d_n)\), such that for all \(i\), \(p_i + d_i + q_i \ge 0\). Then \(\mathit{Pad}[p,q](T)\) is the tensor of shape \((p_1 + d_1 + q_1,\dots,p_n + d_n + q_n)\) such that

\[\begin{split}\mathit{Pad}[p,q](T)_{i_1,\dots,i_n} \triangleq \begin{cases} T_{i_1 - p_1,\dots,i_n - p_n} &\mbox{if for all }j, i_j \ge p_j\mbox{ and }i_j < p_j + d_j \\ 0 &\mbox{otherwise.} \end{cases}\end{split}\]

Dilation

Let \(l\) (the dilation strides) be a sequence of \(n\) positive integers, and \(T\) be a tensor of shape \((d_1,\dots,d_n)\). Then \(\mathit{Dilate}[l](T)\) is the tensor of shape \((d'_1,\dots,d'_n)\) where \(d'_i = \mathit{max}(0,l_i(d_i - 1) + 1)\) such that

\[\begin{split}\mathit{Dilate}[l](T)_{i_1,\dots,i_n} \triangleq \begin{cases} T_{i_1/l_1,\dots,i_n/l_n} &\mbox{if for all }j, i_j\mbox{ is a multiple of }l_j \\ 0 &\mbox{otherwise.} \end{cases}\end{split}\]

Striding

Let \(s\) (the strides) be a sequence of \(n\) positive integers, and \(T\) be a tensor of shape \((d_1,\dots,d_n)\). Then \(\mathit{Stride}[s](T)\) is the tensor of shape \((d'_1,\dots,d'_n)\) where \(d'_i = \left\lceil \frac{d_i}{s_i} \right\rceil\) such that

\[\mathit{Stride}[s](T)_{i_1,\dots,i_n} \triangleq T_{s_1i_1,\dots,s_ni_n}\]

\(s\) is the how far, not the unit of farness.

Convolution

Padded, Dilated, Strided Convolution

\[\mathit{PDSConv}[g,p,q,l,s](T_\mathit{image},T_\mathit{filter} \triangleq \mathit{Stride}[s](\mathit{Conv}(\mathit{Pad}[p,q](\mathit{Dilate}[g](T_\mathit{batch})),\mathit{Dilate}[l](T_\mathit{filter})))\]

Batched, Padded, Dilated, Strided Convolution

C++ Interface

class Convolution : public ngraph::op::Op

Batched convolution operation, with optional window dilation and stride.

Public Functions

const std::string &description() const

Get the string name for the type of the node, such as Add or Multiply. The class name, must not contain spaces as it is used for codegen.

Return

A const reference to the node’s type name

Convolution()

Constructs a batched convolution operation.

Convolution(const Output<Node> &data_batch, const Output<Node> &filters, const Strides &window_movement_strides, const Strides &window_dilation_strides, const CoordinateDiff &padding_below, const CoordinateDiff &padding_above, const Strides &data_dilation_strides, const PadType &pad_type = PadType::EXPLICIT)

Constructs a batched convolution operation.

Output [N, C_OUT, R1, ... Rf]

Parameters
  • data_batch: The node producing the input data batch tensor.[N, C_IN, D1, ... Df]

  • filters: The node producing the filters tensor.[C_OUT, C_IN, F1, ... Ff]

  • window_movement_strides: The window movement strides.[f]

  • window_dilation_strides: The window dilation strides.[f]

  • padding_below: The padding-below sizes.[f]

  • padding_above: The padding-above sizes.[f]

  • data_dilation_strides: The data dilation strides.[f]

  • pad_type: The pad type for automatically computing padding sizes.[f]

Convolution(const Output<Node> &data_batch, const Output<Node> &filters, const Strides &window_movement_strides, const Strides &window_dilation_strides, const CoordinateDiff &padding_below, const CoordinateDiff &padding_above)

Constructs a batched convolution operation with no data dilation (i.e., all data dilation strides are 1).

Output [N, C_OUT, R1, ... Rf]

Parameters
  • data_batch: The node producing the input data batch tensor.[N, C_IN, D1, ... Df]

  • filters: The node producing the filters tensor.[C_OUT, C_IN, F1, ... Ff]

  • window_movement_strides: The window movement strides.[f]

  • window_dilation_strides: The window dilation strides.[f]

  • padding_below: The padding-below sizes.[f]

  • padding_above: The padding-above sizes.[f]

Convolution(const Output<Node> &data_batch, const Output<Node> &filters, const Strides &window_movement_strides, const Strides &window_dilation_strides)

Constructs a batched convolution operation with no padding or data dilation (i.e., padding above and below are 0 everywhere, and all data dilation strides are 1).

Output [N, C_OUT, R1, ... Rf]

Parameters
  • data_batch: The node producing the input data batch tensor.[N, C_IN, D1, ... Df]

  • filters: The node producing the filters tensor.[C_OUT, C_IN, F1, ... Ff]

  • window_movement_strides: The window movement strides.[f]

  • window_dilation_strides: The window dilation strides.[f]

Convolution(const Output<Node> &data_batch, const Output<Node> &filters, const Strides &window_movement_strides)

Constructs a batched convolution operation with no window dilation, padding, or data dilation (i.e., padding above and below are 0 everywhere, and all window/data dilation strides are 1).

Output [N, C_OUT, R1, ... Rf]

Parameters
  • data_batch: The node producing the input data batch tensor.[N, C_IN, D1, ... Df]

  • filters: The node producing the filters tensor.[C_OUT, C_IN, F1, ... Ff]

  • window_movement_strides: The window movement strides.[f]

Convolution(const Output<Node> &data_batch, const Output<Node> &filters)

Constructs a batched convolution operation with no window dilation or movement stride (i.e., padding above and below are 0 everywhere, and all window/data dilation strides and window movement strides are 1).

Output [N, C_OUT, R1, ... Rf]

Parameters
  • data_batch: The node producing the input data batch tensor.[N, C_IN, D1, ... Df]

  • filters: The node producing the filters tensor.[C_OUT, C_IN, F1, ... Ff]

void validate_and_infer_types()

Throws if the node is invalid.

const Strides &get_window_movement_strides() const

Return

The window movement strides.

const Strides &get_window_dilation_strides() const

Return

The window dilation strides.

const CoordinateDiff &get_padding_below() const

Return

The padding-below sizes (possibly negative).

const CoordinateDiff &get_padding_above() const

Return

The padding-above sizes (possibly negative).

const Strides &get_data_dilation_strides() const

Return

The input data dilation strides.

const PadType &get_pad_type() const

Return

The pad type for convolution.

virtual std::shared_ptr<Node> get_default_value() const

Return

The default value for Convolution.