文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

mindspore.ops.Conv2D

class mindspore.ops.Conv2D(out_channel, kernel_size, mode=1, pad_mode='valid', pad=0, stride=1, dilation=1, group=1, data_format='NCHW')[source]

2D convolution layer.

Applies a 2D convolution over an input tensor which is typically of shape (N,Cin,Hin,Win), where N is batch size, C is channel number, H is height, 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,Hin,Win), the formula is defined as:

outj=i=0Cin1ccor(Wij,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. Wij is a slice of kernel and it has shape (kernel_size[0],kernel_size[1]), where kernel_size[0] and kernel_size[1] are the height and width of the convolution kernel. The full kernel has shape (Cout,Cin/group,kernel_size[0],kernel_size[1]), where group is the group number to split the input in the channel dimension.

If the ‘pad_mode’ is set to be “valid”, the output height and width will be 1+Hin+padding[0]+padding[1]kernel_size[0](kernel_size[0]1)×(dilation[0]1)stride[0] and 1+Win+padding[2]+padding[3]kernel_size[1](kernel_size[1]1)×(dilation[1]1)stride[1] respectively. 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.

The first introduction can be found in paper Gradient Based Learning Applied to Document Recognition. More detailed introduction can be found here: http://cs231n.github.io/convolutional-networks/.

Parameters
  • out_channel (int) – The number of output channel Cout.

  • kernel_size (Union[int, tuple[int]]) – The data type is int or a tuple of 2 integers. Specifies the height and width of the 2D convolution window. Single int means the value is for both the height and the width of the kernel. A tuple of 2 ints means the first value is for the height and the other is for the width of the kernel.

  • mode (int) – Modes for different convolutions. 0 Math convolution, 1 cross-correlation convolution , 2 deconvolution, 3 depthwise convolution. Default: 1.

  • pad_mode (str) –

    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 top and bottom, left and right possiblily. Otherwise, the last extra padding will be calculated from the bottom and the right side. If this mode is set, pad must be 0.

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

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

  • pad (Union(int, tuple[int])) – Implicit paddings on both sides of the input x. If pad is one integer, the paddings of top, bottom, left and right are the same, equal to pad. If pad is a tuple with four integers, the paddings of top, bottom, left and right will be equal to pad[0], pad[1], pad[2], and pad[3] accordingly. Default: 0.

  • stride (Union(int, tuple[int])) – The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1.

  • dilation (Union(int, tuple[int])) – The data type is int or a tuple of 2 integers. 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 height and width of the input x. Default: 1.

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

  • data_format (str) – The optional value for data format, is ‘NHWC’ or ‘NCHW’. Default: “NCHW”.

Inputs:
  • x (Tensor) - Tensor of shape (N,Cin,Hin,Win).

  • weight (Tensor) - Set size of kernel is (kernel_size[0],kernel_size[1]), then the shape is (Cout,Cin,kernel_size[0],kernel_size[1]).

Outputs:

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

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

  • TypeError – If out_channel or group is not an int.

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

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

  • ValueError – If pad is a tuple whose length is not equal to 4.

  • ValueError – If pad_mode it not equal to ‘pad’ and pad is not equal to (0, 0, 0, 0).

  • ValueError – If data_format is neither ‘NCHW’ nor ‘NHWC’.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.ones([10, 32, 32, 32]), mindspore.float32)
>>> weight = Tensor(np.ones([32, 32, 3, 3]), mindspore.float32)
>>> conv2d = ops.Conv2D(out_channel=32, kernel_size=3)
>>> output = conv2d(x, weight)
>>> print(output.shape)
(10, 32, 30, 30)