deform_conv2d¶
- torchvision.ops.deform_conv2d(input: Tensor, offset: Tensor, weight: Tensor, bias: Optional[Tensor] = None, stride: Tuple[int, int] = (1, 1), padding: Tuple[int, int] = (0, 0), dilation: Tuple[int, int] = (1, 1), mask: Optional[Tensor] = None) Tensor [源代码]¶
执行可变形卷积 v2,如 可变形卷积网络 v2:更可变形,更好的结果 中所述,如果
mask
不是None
,并且执行可变形卷积,如 可变形卷积网络 中所述,如果mask
是None
。- 参数:
input (Tensor[batch_size, in_channels, in_height, in_width]) – 输入张量
offset (Tensor[batch_size, 2 * offset_groups * kernel_height * kernel_width, out_height, out_width]) – 用于卷积核中每个位置的偏移量。
weight (Tensor[out_channels, in_channels // groups, kernel_height, kernel_width]) – 卷积权重,分成大小为 (in_channels // groups) 的组
bias (Tensor[out_channels]) – 形状为 (out_channels,) 的可选偏差。默认值:None
mask (Tensor[batch_size, offset_groups * kernel_height * kernel_width, out_height, out_width]) – 用于卷积核中每个位置的掩码。默认值:None
- 返回:
卷积的结果
- 返回类型:
Tensor[batch_sz, out_channels, out_h, out_w]
- 示例:
>>> input = torch.rand(4, 3, 10, 10) >>> kh, kw = 3, 3 >>> weight = torch.rand(5, 3, kh, kw) >>> # offset and mask should have the same spatial size as the output >>> # of the convolution. In this case, for an input of 10, stride of 1 >>> # and kernel size of 3, without padding, the output size is 8 >>> offset = torch.rand(4, 2 * kh * kw, 8, 8) >>> mask = torch.rand(4, kh * kw, 8, 8) >>> out = deform_conv2d(input, offset, weight, mask=mask) >>> print(out.shape) >>> # returns >>> torch.Size([4, 5, 8, 8])