昇腾社区首页
中文
注册

beta)torch_npu.contrib.DCNv2

该接口计划废弃,可以使用torch_npu.contrib.ModulationDeformCon接口进行替换。

接口原型

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。

支持的型号

  • Atlas 训练系列产品
  • Atlas A2 训练系列产品
  • Atlas 推理系列产品

调用示例

>>> x = torch.randn((2, 2, 5, 5), dtype=torch.float32).npu()
>>> x.requires_grad = True
>>> model = torch_npu.contrib.DCNv2(2, 2, 3, 2, 1).npu()
>>> output = model(x)
>>> output.sum().backward()