r"""Region Restricted convolution operation. Refer to :class:`~.RegionRestrictedConv` for more information. Args: inp: feature map of the convolution operation. weight: convolution kernel. rin: input mask rout: output mask bias: bias added to the res
(
inp: Tensor,
weight: Tensor,
rin: Tensor,
rout: Tensor,
bias: Optional[Tensor] = None,
stride: Union[int, Tuple[int, int, int]] = 1,
padding: Union[int, Tuple[int, int, int]] = 0,
dilation: Union[int, Tuple[int, int, int]] = 1,
groups: int = 1,
conv_mode: str = "cross_correlation",
compute_mode="default",
)
| 1989 | |
| 1990 | |
| 1991 | def region_restricted_conv( |
| 1992 | inp: Tensor, |
| 1993 | weight: Tensor, |
| 1994 | rin: Tensor, |
| 1995 | rout: Tensor, |
| 1996 | bias: Optional[Tensor] = None, |
| 1997 | stride: Union[int, Tuple[int, int, int]] = 1, |
| 1998 | padding: Union[int, Tuple[int, int, int]] = 0, |
| 1999 | dilation: Union[int, Tuple[int, int, int]] = 1, |
| 2000 | groups: int = 1, |
| 2001 | conv_mode: str = "cross_correlation", |
| 2002 | compute_mode="default", |
| 2003 | ) -> Tensor: |
| 2004 | r"""Region Restricted convolution operation. |
| 2005 | |
| 2006 | Refer to :class:`~.RegionRestrictedConv` for more information. |
| 2007 | |
| 2008 | Args: |
| 2009 | inp: feature map of the convolution operation. |
| 2010 | weight: convolution kernel. |
| 2011 | rin: input mask |
| 2012 | rout: output mask |
| 2013 | bias: bias added to the result of convolution (if given). |
| 2014 | stride: stride of the 2D region restricted convolution operation. Default: 1 |
| 2015 | padding: size of the paddings added to the input on both sides of its |
| 2016 | spatial dimensions. Only zero-padding is supported. Default: 0 |
| 2017 | dilation: dilation of the 2D convolution operation. Default: 1 |
| 2018 | groups: number of groups into which the input and output channels are divided, |
| 2019 | so as to perform a ``grouped convolution``. When ``groups`` is not 1, |
| 2020 | ``in_channels`` and ``out_channels`` must be divisible by ``groups``, |
| 2021 | and the shape of weight should be ``(groups, out_channel // groups, |
| 2022 | in_channels // groups, depth, height, width)``. Default: 1 |
| 2023 | conv_mode: supports "cross_correlation". Default: "cross_correlation" |
| 2024 | |
| 2025 | Returns: |
| 2026 | output tensor. |
| 2027 | """ |
| 2028 | assert conv_mode.lower() == "cross_correlation" |
| 2029 | |
| 2030 | pad_h, pad_w = expand_hw(padding) |
| 2031 | stride_h, stride_w = expand_hw(stride) |
| 2032 | dilate_h, dilate_w = expand_hw(dilation) |
| 2033 | |
| 2034 | sparse_type = "group" |
| 2035 | assert groups > 0, ( |
| 2036 | "RegionRestrictedConv expected grouped conv mode, \ |
| 2037 | which requires groups > 0, but got groups=%d" |
| 2038 | % (groups) |
| 2039 | ) |
| 2040 | op = builtin.RegionRestrictedConvolution( |
| 2041 | stride_h=stride_h, |
| 2042 | stride_w=stride_w, |
| 2043 | pad_h=pad_h, |
| 2044 | pad_w=pad_w, |
| 2045 | dilate_h=dilate_h, |
| 2046 | dilate_w=dilate_w, |
| 2047 | mode=conv_mode, |
| 2048 | compute_mode=compute_mode, |