捷徑

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。如果 maskNone,則執行 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

  • stride (intTuple[int, int]) – 卷積中心之間的距離。預設值:1

  • padding (intTuple[int, int]) – 每個圖像周圍零填充的高度/寬度。預設值:0

  • dilation (intTuple[int, int]) – 核心元素之間的間距。預設值:1

  • 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])

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得初學者和進階開發者的深入教學課程

檢視教學

資源

尋找開發資源並取得您問題的解答

檢視資源