Esempio n. 1
0
    def deform_sampling(self, feat, offset):
        """Sampling the feature x according to offset.

        Args:
            feat (Tensor): Feature
            offset (Tensor): Spatial offset for for feature sampliing
        """
        # it is an equivalent implementation of bilinear interpolation
        b, c, h, w = feat.shape
        weight = feat.new_ones(c, 1, 1, 1)
        y = deform_conv2d(feat, offset, weight, 1, 0, 1, c, c)
        return y
Esempio n. 2
0
    def forward(self, i, x):

        if i < self.start_level:
            return torch.nn.functional.conv2d(x,
                                              self.weight,
                                              bias=self.bias,
                                              stride=self.stride,
                                              padding=self.padding,
                                              dilation=self.dilation,
                                              groups=self.groups)

        offset = self.conv_offset(x)
        return deform_conv2d(x, offset, self.weight, self.stride, self.padding,
                             self.dilation, self.groups,
                             self.deform_groups) + self.bias.unsqueeze(
                                 0).unsqueeze(-1).unsqueeze(-1)
Esempio n. 3
0
 def forward(self, x, extra_feat):
     offset = self.conv_offset(extra_feat)
     return deform_conv2d(x, offset, self.weight, self.stride, self.padding,
                          self.dilation, self.groups, self.deform_groups)