def forward( ctx, input, offset, mask, weight, bias, stride, padding, dilation, deformable_groups ): ctx.stride = _pair(stride) ctx.padding = _pair(padding) ctx.dilation = _pair(dilation) ctx.kernel_size = _pair(weight.shape[2:4]) ctx.deformable_groups = deformable_groups output = _backend.dcn_v2_forward( input, weight, bias, offset, mask, ctx.kernel_size[0], ctx.kernel_size[1], ctx.stride[0], ctx.stride[1], ctx.padding[0], ctx.padding[1], ctx.dilation[0], ctx.dilation[1], ctx.deformable_groups, ) ctx.save_for_backward(input, offset, mask, weight, bias) return output
def forward(ctx, input, offset_mask, weight, bias, stride, padding, dilation, deformable_groups): ctx.stride = _pair(stride) ctx.padding = _pair(padding) ctx.dilation = _pair(dilation) ctx.kernel_size = _pair(weight.shape[2:4]) ctx.deformable_groups = deformable_groups o1, o2, mask = torch.chunk(offset_mask, 3, dim=1) offset = torch.cat((o1, o2), dim=1) mask = torch.sigmoid(mask) # @staticmethod # def forward(ctx, input, offset, mask, weight, bias, # stride, padding, dilation, deformable_groups): # ctx.stride = _pair(stride) # ctx.padding = _pair(padding) # ctx.dilation = _pair(dilation) # ctx.kernel_size = _pair(weight.shape[2:4]) # ctx.deformable_groups = deformable_groups output = _backend.dcn_v2_forward( input, weight, bias, offset, mask, ctx.kernel_size[0], ctx.kernel_size[1], ctx.stride[0], ctx.stride[1], ctx.padding[0], ctx.padding[1], ctx.dilation[0], ctx.dilation[1], ctx.deformable_groups) ctx.save_for_backward(input, offset, mask, weight, bias) return output
def forward(self, input, offset, mask): # assert 2 * self.deformable_groups * self.kernel_size[0] * self.kernel_size[1] == \ # offset.shape[1] # assert self.deformable_groups * self.kernel_size[0] * self.kernel_size[1] == \ # mask.shape[1] output = _backend.dcn_v2_forward( input, self.weight, self.bias, offset, mask, self.weight.shape[2], self.weight.shape[3], self.stride[0], self.stride[1], self.padding[0], self.padding[1], self.dilation[0], self.dilation[1], self.deformable_groups) return output
def forward(ctx, input, offset, mask, weight, bias, stride, padding, dilation, deformable_groups): ctx.stride = _pair(stride) ctx.padding = _pair(padding) ctx.dilation = _pair(dilation) ctx.kernel_size = _pair(weight.shape[2:4]) ctx.deformable_groups = deformable_groups # input, offset, mask为输入数据的类型,可能是半精度,apex混合精度转为float # if input.dtype == torch.float16: # weight, bias = weight.half(), bias.half() output = _backend.dcn_v2_forward( input, weight, bias, offset, mask, ctx.kernel_size[0], ctx.kernel_size[1], ctx.stride[0], ctx.stride[1], ctx.padding[0], ctx.padding[1], ctx.dilation[0], ctx.dilation[1], ctx.deformable_groups) ctx.save_for_backward(input, offset, mask, weight, bias) return output
def forward( ctx, input, offset, mask, weight, bias, stride, padding, dilation, deformable_groups, ): if use_amp: input = input.float() offset = offset.float() mask = mask.float() weight = weight.float() bias = bias.float() ctx.stride = _pair(stride) ctx.padding = _pair(padding) ctx.dilation = _pair(dilation) ctx.kernel_size = _pair(weight.shape[2:4]) ctx.deformable_groups = deformable_groups output = _backend.dcn_v2_forward( input, weight, bias, offset, mask, ctx.kernel_size[0], ctx.kernel_size[1], ctx.stride[0], ctx.stride[1], ctx.padding[0], ctx.padding[1], ctx.dilation[0], ctx.dilation[1], ctx.deformable_groups, ) ctx.save_for_backward(input, offset, mask, weight, bias) if use_amp: return output.half() return output