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 [source]¶
如果
mask
不是None
,則執行 Deformable Convolution v2,詳情請見 Deformable ConvNets v2: More Deformable, Better Results。如果mask
是None
,則執行 Deformable Convolution,詳情請見 Deformable Convolutional Networks。- 參數:
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])