MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / local_conv2d

Function local_conv2d

imperative/python/megengine/functional/nn.py:523–571  ·  view source on GitHub ↗

r"""Applies a spatial convolution with untied kernels over an groupped channeled input 4D tensor. It is also known as the locally connected layer. Args: inp: input feature map. weight: convolution kernel. weight usually has shape ``(out_channels, in_channels, hei

(
    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,
    conv_mode="cross_correlation",
)

Source from the content-addressed store, hash-verified

521
522
523def local_conv2d(
524 inp: Tensor,
525 weight: Tensor,
526 bias: Optional[Tensor] = None,
527 stride: Union[int, Tuple[int, int]] = 1,
528 padding: Union[int, Tuple[int, int]] = 0,
529 dilation: Union[int, Tuple[int, int]] = 1,
530 conv_mode="cross_correlation",
531):
532 r"""Applies a spatial convolution with untied kernels over an groupped channeled input 4D tensor.
533 It is also known as the locally connected layer.
534
535 Args:
536 inp: input feature map.
537 weight: convolution kernel.
538 weight usually has shape ``(out_channels, in_channels, height, width)``.
539 bias: bias added to the result of convolution (if given).
540 stride: stride of the 2D convolution operation. Default: 1
541 padding: size of the paddings added to the input on both sides of its
542 spatial dimensions. Only zero-padding is supported. Default: 0
543 dilation: dilation of the 2D convolution operation. Default: 1
544
545 Returns:
546 output tensor.
547 """
548 assert (
549 conv_mode.lower() == "cross_correlation"
550 or conv_mode.name == "CROSS_CORRELATION"
551 )
552
553 stride_h, stride_w = expand_hw(stride)
554 pad_h, pad_w = expand_hw(padding)
555 dilate_h, dilate_w = expand_hw(dilation)
556
557 # local conv only support "dense" mode, but weight could contain group dimension.
558 op = builtin.GroupLocal(
559 stride_h=stride_h,
560 stride_w=stride_w,
561 pad_h=pad_h,
562 pad_w=pad_w,
563 dilate_h=dilate_h,
564 dilate_w=dilate_w,
565 mode=conv_mode,
566 sparse="dense",
567 )
568 (output,) = apply(op, inp, weight)
569 if bias is not None:
570 output += bias
571 return output
572
573
574def conv_transpose3d(

Callers 1

forwardMethod · 0.85

Calls 2

expand_hwFunction · 0.85
applyFunction · 0.50

Tested by

no test coverage detected