| 30 | |
| 31 | |
| 32 | class DeformConvWithOff(nn.Module): |
| 33 | |
| 34 | def __init__(self, in_channels, out_channels, |
| 35 | kernel_size=3, stride=1, padding=1, |
| 36 | dilation=1, deformable_groups=1): |
| 37 | super(DeformConvWithOff, self).__init__() |
| 38 | self.offset_conv = nn.Conv2d( |
| 39 | in_channels, |
| 40 | deformable_groups * 2 * kernel_size * kernel_size, |
| 41 | kernel_size=kernel_size, |
| 42 | stride=stride, |
| 43 | padding=padding, |
| 44 | ) |
| 45 | self.dcn = DeformConv( |
| 46 | in_channels, out_channels, kernel_size=kernel_size, |
| 47 | stride=stride, padding=padding, dilation=dilation, |
| 48 | deformable_groups=deformable_groups, |
| 49 | ) |
| 50 | |
| 51 | def forward(self, input): |
| 52 | offset = self.offset_conv(input) |
| 53 | output = self.dcn(input, offset) |
| 54 | return output |
| 55 | |
| 56 | |
| 57 | class ModulatedDeformConvWithOff(nn.Module): |