deform_conv2d.cpp 2.52 KB
Newer Older
1
#include "deform_conv2d.h"
2
3

#include <torch/types.h>
4

5
6
namespace vision {
namespace ops {
7
8

at::Tensor deform_conv2d(
9
10
11
    const at::Tensor& input,
    const at::Tensor& weight,
    const at::Tensor& offset,
12
    const at::Tensor& mask,
13
    const at::Tensor& bias,
14
15
16
17
18
19
20
    int64_t stride_h,
    int64_t stride_w,
    int64_t pad_h,
    int64_t pad_w,
    int64_t dilation_h,
    int64_t dilation_w,
    int64_t groups,
21
22
    int64_t offset_groups,
    bool use_mask) {
Kai Zhang's avatar
Kai Zhang committed
23
  C10_LOG_API_USAGE_ONCE("torchvision.csrc.ops.deform_conv2d.deform_conv2d");
24
25
26
27
28
29
30
  static auto op = c10::Dispatcher::singleton()
                       .findSchemaOrThrow("torchvision::deform_conv2d", "")
                       .typed<decltype(deform_conv2d)>();
  return op.call(
      input,
      weight,
      offset,
31
      mask,
32
33
34
35
36
37
38
      bias,
      stride_h,
      stride_w,
      pad_h,
      pad_w,
      dilation_h,
      dilation_w,
39
      groups,
40
41
      offset_groups,
      use_mask);
42
43
}

44
45
namespace detail {

46
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor, at::Tensor>
47
48
49
50
51
_deform_conv2d_backward(
    const at::Tensor& grad,
    const at::Tensor& input,
    const at::Tensor& weight,
    const at::Tensor& offset,
52
    const at::Tensor& mask,
53
    const at::Tensor& bias,
54
55
56
57
58
59
60
    int64_t stride_h,
    int64_t stride_w,
    int64_t pad_h,
    int64_t pad_w,
    int64_t dilation_h,
    int64_t dilation_w,
    int64_t groups,
61
62
    int64_t offset_groups,
    bool use_mask) {
63
64
65
66
67
68
69
70
71
  static auto op =
      c10::Dispatcher::singleton()
          .findSchemaOrThrow("torchvision::_deform_conv2d_backward", "")
          .typed<decltype(_deform_conv2d_backward)>();
  return op.call(
      grad,
      input,
      weight,
      offset,
72
      mask,
73
74
75
76
77
78
79
      bias,
      stride_h,
      stride_w,
      pad_h,
      pad_w,
      dilation_h,
      dilation_w,
80
      groups,
81
82
      offset_groups,
      use_mask);
83
84
}

85
86
} // namespace detail

87
TORCH_LIBRARY_FRAGMENT(torchvision, m) {
88
89
90
91
  m.def(TORCH_SELECTIVE_SCHEMA(
      "torchvision::deform_conv2d(Tensor input, Tensor weight, Tensor offset, Tensor mask, Tensor bias, int stride_h, int stride_w, int pad_h, int pad_w, int dilation_h, int dilation_w, int groups, int offset_groups, bool use_mask) -> Tensor"));
  m.def(TORCH_SELECTIVE_SCHEMA(
      "torchvision::_deform_conv2d_backward(Tensor grad, Tensor input, Tensor weight, Tensor offset, Tensor mask, Tensor bias, int stride_h, int stride_w, int pad_h, int pad_w, int dilation_h, int dilation_w, int groups, int offset_groups, bool use_mask) -> (Tensor, Tensor, Tensor, Tensor, Tensor)"));
92
93
}

94
95
} // namespace ops
} // namespace vision