r"""2D convolution operation. Refer to :class:`~.module.Conv2d` for more information. Args: inp: feature map of the convolution operation. weight: convolution kernel. bias: bias added to the result of convolution (if given). stride: stride of the 2D convolut
(
inp: Tensor,
weight: Tensor,
bias: Optional[Tensor] = None,
stride: Union[int, Tuple[int, int]] = 1,
padding: Union[int, Tuple[int, int]] = 0,
dilation: Union[int, Tuple[int, int]] = 1,
groups: int = 1,
conv_mode="cross_correlation",
compute_mode="default",
)
| 222 | |
| 223 | |
| 224 | def conv2d( |
| 225 | inp: Tensor, |
| 226 | weight: Tensor, |
| 227 | bias: Optional[Tensor] = None, |
| 228 | stride: Union[int, Tuple[int, int]] = 1, |
| 229 | padding: Union[int, Tuple[int, int]] = 0, |
| 230 | dilation: Union[int, Tuple[int, int]] = 1, |
| 231 | groups: int = 1, |
| 232 | conv_mode="cross_correlation", |
| 233 | compute_mode="default", |
| 234 | ) -> Tensor: |
| 235 | r"""2D convolution operation. |
| 236 | |
| 237 | Refer to :class:`~.module.Conv2d` for more information. |
| 238 | |
| 239 | Args: |
| 240 | inp: feature map of the convolution operation. |
| 241 | weight: convolution kernel. |
| 242 | bias: bias added to the result of convolution (if given). |
| 243 | stride: stride of the 2D convolution operation. Default: 1 |
| 244 | padding: size of the paddings added to the input on both sides of its |
| 245 | spatial dimensions. Only zero-padding is supported. Default: 0 |
| 246 | dilation: dilation of the 2D convolution operation. Default: 1 |
| 247 | groups: number of groups into which the input and output channels are divided, |
| 248 | so as to perform a ``grouped convolution``. When ``groups`` is not 1, |
| 249 | ``in_channels`` and ``out_channels`` must be divisible by ``groups``, |
| 250 | and the shape of weight should be ``(groups, out_channel // groups, |
| 251 | in_channels // groups, height, width)``. Default: 1 |
| 252 | conv_mode: supports "cross_correlation". Default: "cross_correlation" |
| 253 | compute_mode: when set to "default", no special requirements will be |
| 254 | placed on the precision of intermediate results. When set to "float32", |
| 255 | "float32" would be used for accumulator and intermediate result, but only |
| 256 | effective when input and output are of float16 dtype. |
| 257 | |
| 258 | Returns: |
| 259 | output tensor. |
| 260 | """ |
| 261 | assert ( |
| 262 | conv_mode.lower() == "cross_correlation" |
| 263 | or conv_mode.name == "CROSS_CORRELATION" |
| 264 | ) |
| 265 | |
| 266 | stride_h, stride_w = expand_hw(stride) |
| 267 | pad_h, pad_w = expand_hw(padding) |
| 268 | dilate_h, dilate_w = expand_hw(dilation) |
| 269 | |
| 270 | sparse_type = "dense" if groups == 1 else "group" |
| 271 | compute_mode = _config._get_actual_op_param(compute_mode, _config.__compute_mode) |
| 272 | op = builtin.Convolution( |
| 273 | stride_h=stride_h, |
| 274 | stride_w=stride_w, |
| 275 | pad_h=pad_h, |
| 276 | pad_w=pad_w, |
| 277 | dilate_h=dilate_h, |
| 278 | dilate_w=dilate_w, |
| 279 | strategy=get_execution_strategy(), |
| 280 | mode=conv_mode, |
| 281 | compute_mode=compute_mode, |
no test coverage detected