conv1d#
- ivy.conv1d(x, filters, strides, padding, /, *, data_format='NWC', filter_format='channel_last', x_dilations=1, dilations=1, bias=None, out=None)[source]#
Compute a 1-D convolution given 3-D input x and filters arrays.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input image [batch_size,w,d_in] or [batch_size,d_in,w].filters (
Union
[Array
,NativeArray
]) – Convolution filters [fw,d_in,d_out].strides (
Union
[int
,Tuple
[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:'NWC'
) – The ordering of the dimensions in the input, one of “NWC” or “NCW”. “NWC” corresponds to input with shape (batch_size, width, channels), while “NCW” corresponds to input with shape (batch_size, channels, width).filter_format (
str
, default:'channel_last'
) –- Either “channel_first” or “channel_last”. “channel_first” corresponds to “OIW”,
input data formats, while “channel_last” corresponds to “WIO”, “HWIO”, “DHWIO”.
- x_dilations
The dilation factor for each dimension of input. (Default value = 1)
dilations (
Union
[int
,Tuple
[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:
- 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.asarray([[[0.], [3.], [0.]]]) #NWC >>> filters = ivy.array([[[0.]], [[1.]], [[0.]]]) #WIO >>> result = ivy.conv1d(x, filters, (1,), 'SAME', data_format='NWC',dilations= (1,)) >>> print(result) ivy.array([[[0.], [3.], [0.]]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([[[1., 3.], [2., 4.], [5., 7]]]) >>> filters = ivy.native_array([[[0., 1.], [1., 0.]]]) >>> result = ivy.conv1d(x, filters, (2,),'VALID') >>> print(result) ivy.array([[[3., 1.], ... [7., 5.]]])
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([[[1.2, 3.1, 4.8], [5.9, 2.2, 3.3], ... [10.8, 7.6, 4.9], [6.1, 2.2, 9.5]]]), ... b=ivy.array([[[8.8, 7.7, 6.6], [1.1, 2.2, 3.5]]])) >>> filters = ivy.array([[[1., 0., 1.], [0., 1., 0.], [1., 1., 0.]]]) >>> result = ivy.conv1d(x, filters, 3, 'VALID') >>> print(result) { a: ivy.array([[[6., 7.9, 1.2], ... [15.6, 11.7, 6.1]]]), ... b: ivy.array([[[15.4, 14.3, 8.8]]]) }
- Array.conv1d(self, filters, strides, padding, /, *, data_format='NWC', filter_format='channel_last', x_dilations=1, dilations=1, bias=None, out=None)[source]#
ivy.Array instance method variant of ivy.conv1d. This method simply wraps the function, and so the docstring for ivy.conv1d also applies to this method with minimal changes.
- Parameters:
self (
Array
) – Input image [batch_size,w,d_in] or [batch_size,d_in,w].filters (
Union
[Array
,NativeArray
]) – Convolution filters [fw,d_in,d_out].strides (
Union
[int
,Tuple
[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:'NWC'
) – “NWC” or “NCW”. Defaults to “NWC”.filter_format (
str
, default:'channel_last'
) –Either “channel_first” or “channel_last”. Defaults to “channel_last”. x_dilations
The dilation factor for each dimension of input. (Default value = 1)
dilations (
Union
[int
,Tuple
[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.array([[[1., 2.], [3., 4.], [6., 7.], [9., 11.]]]) # NWC >>> filters = ivy.array([[[0., 1.], [1., 1.]]]) # WIO (I == C) >>> result = x.conv1d(filters, (1,), 'VALID') >>> print(result) ivy.array([[[ 2., 3.], ... [ 4., 7.], ... [ 7., 13.], ... [11., 20.]]])
- Container.conv1d(self, filters, strides, padding, /, *, data_format='NWC', 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.conv1d. This method simply wraps the function, and so the docstring for ivy.conv1d also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input image [batch_size,w, d_in].filters (
Union
[Array
,NativeArray
,Container
]) – Convolution filters [fw,d_in, d_out]. (d_in must be the same as d from x)strides (
Union
[int
,Tuple
[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:'NWC'
) – “NWC” or “NCW”. Defaults to “NWC”.filter_format (
str
, default:'channel_last'
) – Either “channel_first” or “channel_last”. Defaults to “channel_last”.x_dilations (
Union
[int
,Tuple
[int
]], default:1
) – The dilation factor for each dimension of input. (Default value = 1)dilations (
Union
[int
,Tuple
[int
]], default:1
) – The dilation factor for each dimension of input. (Default value = 1)key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
bool
, default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
bool
, default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
bool
, default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.bias (
Optional
[Container
], default:None
) – Bias array of shape [d_out].out (
Optional
[Container
], default:None
) – optional output container, 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.array([[[2., 3., 4.], [5., 6., 7.]]]), ... b=ivy.array([[[7., 8., 9.], [10., 11., 12]]])) >>> filters = ivy.array([[[0., 0.5, 1.], [0.25, 0.5, 0.75], [-0.5, 0., 0.5 ]]]) >>> result= x.conv1d(filters, (1,), 'VALID') >>> print(result) { ... a: ivy.array([[[-1.25, 2.5, 6.25], ... [-2., 5.5, 13.]]]), ... b: ivy.array([[[-2.5, 7.5, 17.5], ... [-3.25, 10.5, 24.2]]]) }