conv3d#

ivy.conv3d(x, filters, strides, padding, /, *, data_format='NDHWC', filter_format='channel_last', x_dilations=1, dilations=1, bias=None, out=None)[source]#

Compute a 3-D convolution given 5-D input x and filters arrays.

Parameters:
  • x (Union[Array, NativeArray, Container]) – Input volume [batch_size,d,h,w,d_in] or [batch_size,d_in,d,h,w].

  • filters (Union[Array, NativeArray, Container]) – Convolution filters [fd,fh,fw,d_in,d_out].

  • strides (Union[int, Tuple[int, int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (Union[str, int, Sequence[Tuple[int, int]]]) – either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.

  • data_format (str, default: 'NDHWC') – The ordering of the dimensions in the input, one of “NDHWC” or “NCDHW”. “NDHWC” corresponds to inputs with shape (batch_size, depth, height, width, channels), while “NCDHW” corresponds to input with shape (batch_size, channels, depth, height, width).

  • filter_format (str, default: 'channel_last') –

    Either “channel_first” or “channel_last”. “channel_first” corresponds

    to “OIDHW”,input data formats, while “channel_last” corresponds to “DHWIO”.

    x_dilations

    The dilation factor for each dimension of input. (Default value = 1)

  • dilations (Union[int, Tuple[int, int, int]], default: 1) – The dilation factor for each dimension of input. (Default value = 1)

  • bias (Optional[Array], default: None) – Bias array of shape [d_out]

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

  • ret – The result of the convolution operation.

  • Both the description and the type hints above assumes an array input for simplicity,

  • but this function is nestable, and therefore also accepts ivy.Container

  • instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([[[1., 2. ,1.], [1., 2. ,1.], [1., 2. ,1.]],
...         [[1., 2. ,1.], [1., 2. ,1.], [1., 2. ,1.]],
...         [[1., 2. ,1.], [1., 2. ,1.], [1., 2. ,1.]]]).reshape((1, 3, 3, 3, 1))
>>> filters = ivy.array([[[0.,1.,0.],
...                       [0.,1.,0.],
...                       [0.,1.,0.]]]).reshape((1,3,3,1,1))
>>> result = ivy.conv3d(x, filters, 1, 'SAME', data_format='NDHWC', dilations=1)
>>> print(result)
ivy.array([[[[[2.],[4.],[2.]],[[3.],[6.],[3.]],[[2.],[4.],[2.]]],
            [[[2.],[4.],[2.]],[[3.],[6.],[3.]],[[2.],[4.],[2.]]],
            [[[2.],[4.],[2.]],[[3.],[6.],[3.]],[[2.],[4.],[2.]]]]])

With one ivy.Container input:

>>> x = ivy.Container(a = ivy.ones((1, 3, 3, 3, 1)).astype(ivy.float32))
>>> filters = ivy.ones((3, 3, 3, 1, 1)).astype(ivy.float32)
>>> result = ivy.conv3d(x, filters, 2, 'SAME')
>>> print(result)
{
    a: ivy.array([[[[[8.],[8.]],[[8.],[8.]]],[[[8.],[8.]],[[8.],[8.]]]]])
}

With multiple ivy.Container input:

>>> x = ivy.Container( a = ivy.random_normal(mean = 0, std = 1,
...                        shape = [1, 3, 5, 5, 1]),
...                    b = ivy.random_normal(mean = 0, std = 1,
...                        shape = [1, 5, 32 ,32, 1]),
...                    c = ivy.random_normal(mean = 0, std = 1,
...                        shape = [1, 32, 32, 32, 1]))
>>> filters = ivy.ones((3, 5, 5, 1, 3)).astype(ivy.float32)
>>> result = ivy.conv3d(x, filters, 1, 'SAME')
>>> print(result.cont_shapes)
{
    a: ivy.Shape(1, 3, 5, 5, 3),
    b: ivy.Shape(1, 5, 32, 32, 3),
    c: ivy.Shape(1, 32, 32, 32, 3)
}
Array.conv3d(self, filters, strides, padding, /, *, data_format='NDHWC', filter_format='channel_last', x_dilations=1, dilations=1, bias=None, out=None)[source]#

ivy.Array instance method variant of ivy.conv3d. This method simply wraps the function, and so the docstring for ivy.conv3d also applies to this method with minimal changes.

Parameters:
  • x – Input volume [batch_size,d,h,w,d_in].

  • filters (Union[Array, NativeArray]) – Convolution filters [fd,fh,fw,d_in,d_out].

  • strides (Union[int, Tuple[int, int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (str) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NDHWC') – “NDHWC” or “NCDHW”. Defaults to “NDHWC”.

  • filter_format (str, default: 'channel_last') – Either “channel_first” or “channel_last”. Defaults to “channel_last”.

  • x_dilations (Union[int, Tuple[int, int, int]], default: 1) – The dilation factor for each dimension of input. (Default value = 1)

  • dilations (Union[int, Tuple[int, int, int]], default: 1) – The dilation factor for each dimension of input. (Default value = 1)

  • bias (Optional[Array], default: None) – Bias array of shape [d_out].

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The result of the convolution operation.

Examples

>>> x = ivy.ones((1, 3, 3, 3, 1)).astype(ivy.float32)
>>> filters = ivy.ones((1, 3, 3, 1, 1)).astype(ivy.float32)
>>> result = x.conv3d(filters, 2, 'SAME')
>>> print(result)
ivy.array([[[[[4.],[4.]],[[4.],[4.]]],[[[4.],[4.]],[[4.],[4.]]]]])
Container.conv3d(self, filters, strides, padding, /, *, data_format='NDHWC', filter_format='channel_last', x_dilations=1, dilations=1, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, bias=None, out=None)[source]#

ivy.Container instance method variant of ivy.conv3d. This method simply wraps the function, and so the docstring for ivy.conv3d also applies to this method with minimal changes.

Parameters:
  • x – Input volume [batch_size,d,h,w,d_in].

  • filters (Union[Array, NativeArray, Container]) – Convolution filters [fdfh,fw,d_in,d_out].

  • strides (Union[int, Tuple[int, int, int], Container]) – The stride of the sliding window for each dimension of input.

  • padding (Union[str, Container]) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str, default: 'NDHWC') – “NDHWC” or “NCDHW”. Defaults to “NDHWC”.

  • filter_format (str, default: 'channel_last') – Either “channel_first” or “channel_last”. Defaults to “channel_last”.

  • x_dilations (Union[int, Tuple[int, int, int]], default: 1) – The dilation factor for each dimension of input. (Default value = 1)

  • dilations (Union[int, Tuple[int, int, int]], default: 1) – The dilation factor for each dimension of input. (Default value = 1)

  • bias (Optional[Container], default: None) – Bias array of shape [d_out].

  • out (Optional[Container], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – The result of the convolution operation.

Examples

>>> x = ivy.Container(a = ivy.full((1, 2, 3, 3, 1),0.5),                              b = ivy.full((1, 2, 5, 5, 1),1.))
>>> filters = ivy.ones((3, 3, 3, 1, 1))
>>> result = x.conv3d(filters, 2, 'SAME')
>>> print(result)
{
    a: ivy.array([[[[[4.],[4.]],[[4.],[4.]]]]]),
    b: ivy.array([[[[[8.],[12.],[8.]],[[12.],[18.],[12.]],[[8.],[12.],[8.]]]]])
}