昇腾社区首页
中文
注册

torch_npu.contrib.DCNv2

API接口

torch_npu.contrib.DCNv2(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, deformable_groups=1, bias=True, pack=True)

功能描述

应用基于NPU的调制可变形2D卷积操作。ModulationDeformConv的实现主要是基于mmcv的实现进行设计和重构。

参数说明

  • in_channels (int):Number of channels in the input image.=
  • out_channels (int):Number of channels produced by the convolution.
  • kernel_size(int, tuple):Size of the convolving kernel.
  • stride(int, tuple):Stride of the convolution. Default: 1.
  • padding (int or tuple):Zero-padding added to both sides of the input.
  • Default:0.
  • dilation (int or tuple):Spacing between kernel elements. Default:1.
  • groups (int):Number of blocked connections from input.
  • channels to output channels. Default:1.
  • deform_groups (int):Number of deformable group partitions.
  • bias (bool):If True, adds a learnable bias to the output. Default:False.
  • pack (bool):If True, conv_offset and mask will be included in this module. Default:True.

约束说明

ModedDeformConv仅实现fp32数据类型下的操作。注意,con_offset中的权重和偏置必须初始化为0。

示例

   >>> m = ModulatedDeformConv(32, 32, 1)
   >>> input_tensor = torch.randn(2, 32, 5, 5)
   >>> output = m(input_tensor)

   >>> x = torch.randn(2, 32, 7, 7)
   >>> model = ModulatedDeformConv(32, 32, 3, 2, 1)

   >>> torch.npu.set_device(0)
   >>> x = x.npu()
   >>> model = model.npu()

   >>> o = model(x)
   >>> l = o.sum()
   >>> l.backward()
   >>> print(l)