Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.conv1d

mindspore.ops.conv1d(input, weight, bias=None, stride=1, pad_mode='valid', padding=0, dilation=1, groups=1)[source]

Applies a 1D convolution over an input tensor. The input tensor is typically of shape (N,Cin,Win), where N is batch size, Cin is channel number, W is width, Xi is the ith input value and bi indicates the deviation value of the ith input value. For each batch of shape (Cin,Win), the formula is defined as:

outj=i=0Cin1ccor(Wj,Xi)+bj,

where ccor is the cross-correlation operator, Cin is the input channel number, j ranges from 0 to Cout1, Wij corresponds to the i-th channel of the j-th filter and outj corresponds to the j-th channel of the output. Wj is a slice of kernel, and it has shape (kernal_size), where kernel_size is the width of the convolution kernel. The full kernel has shape (Cout,Cin/groups,kernel_size), where groups is the group number to split the input in the channel dimension.

If the pad_mode is set to be “valid”, the output width will be 1+Win+padding[0]kernel_size(kernel_size1)×(dilation1) stride .

where dilation is spacing between kernel elements, stride is The step length of each step, padding is zero-padding added to both sides of the input. For output width on other pad_mode, please refer to formula on mindspore.nn.Conv1d.

The first introduction can be found in paper Gradient Based Learning Applied to Document Recognition. More detailed introduction can be found here: ConvNets .

Note

On Ascend platform, only group convolution in depthwise convolution scenarios is supported. That is, when groups>1, condition C_{in} = C_{out} = groups must be satisfied.

Parameters
  • input (Tensor) – Tensor of shape (N,Cin,Win).

  • weight (Tensor) – Tensor of shape (N,Cin/groups,kernel_size), then the size of kernel is (kernel_size).

  • bias (Tensor) – Bias Tensor with shape (Cout). When bias is None, zeros will be used. Default: None.

  • stride (Union(int, tuple[int]), optional) – The distance of kernel moving, an int number or a tuple of one int that represents width of movement. Default: 1.

  • pad_mode (str, optional) –

    Specifies padding mode. The optional values are “same”, “valid” and “pad”. Default: “valid”.

    • same: Adopts the way of completion. The height and width of the output will be equal to the input x divided by stride. The padding will be evenly calculated in left and right possiblily. Otherwise, the last extra padding will be calculated from the right side. If this mode is set, padding must be 0.

    • valid: Adopts the way of discarding. The possible largest width of output will be returned without padding. Extra pixels will be discarded. If this mode is set, padding must be 0.

    • pad: Implicit paddings on both sides of the input x. The number of padding will be padded to the input Tensor borders. padding must be greater than or equal to 0.

  • padding (Union(int, tuple[int]), optional) – Implicit paddings on both sides of input, meaning the paddings of left and right are the same, equal to padding or padding[0] when padding is a tuple of 1 integer. Default: 0.

  • dilation (Union(int, tuple[int]), optional) – Gaps between kernel elements. The data type is int or a tuple of 1 integer. Specifies the dilation rate to use for dilated convolution. If set to be k>1, there will be k1 pixels skipped for each sampling location. Its value must be greater than or equal to 1 and bounded by the width of input. Default: 1.

  • groups (int, optional) – Splits input into groups. Default: 1.

Returns

Tensor, the value that applied 1D convolution. The shape is (N,Cout,Wout).

Raises
  • TypeError – If stride, padding or dilation is neither an int nor a tuple.

  • TypeErrorgroups is not an int.

  • TypeError – If bias is not a Tensor.

  • ValueError – If the shape of bias is not (Cout) .

  • ValueError – If stride or dilation is less than 1.

  • ValueError – If pad_mode is not one of ‘same’, ‘valid’ or ‘pad’.

  • ValueError – If padding is a tuple whose length is not equal to 1.

  • ValueError – If pad_mode is not equal to ‘pad’ and padding is greater than 0.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.arange(64).reshape((4, 4, 4)), mindspore.float32)
>>> weight = Tensor(np.arange(8).reshape((2, 2, 2)), mindspore.float32)
>>> bias = Tensor([-0.12345, 2.7683], ms.float32)
>>> output = ops.conv1d(x, weight, pad_mode='pad', padding=(1,), bias=bias, groups=2)
>>> print(output.shape)
(4, 2, 5)