roi_align.cpp 2.04 KB
Newer Older
1
#include "roi_align.h"
2
3

#include <torch/types.h>
4

5
6
namespace vision {
namespace ops {
7
8

at::Tensor roi_align(
9
10
    const at::Tensor& input, // Input feature map.
    const at::Tensor& rois, // List of ROIs to pool over.
11
    double spatial_scale, // The scale of the image features. ROIs will be
12
    // scaled to this.
13
14
15
16
    int64_t pooled_height, // The height of the pooled feature map.
    int64_t pooled_width, // The width of the pooled feature
    int64_t sampling_ratio, // The number of points to sample in each bin
    bool aligned) // The flag for pixel shift
17
18
// along each axis.
{
19
20
21
22
  static auto op = c10::Dispatcher::singleton()
                       .findSchemaOrThrow("torchvision::roi_align", "")
                       .typed<decltype(roi_align)>();
  return op.call(
Francisco Massa's avatar
Francisco Massa committed
23
24
25
26
27
28
29
      input,
      rois,
      spatial_scale,
      pooled_height,
      pooled_width,
      sampling_ratio,
      aligned);
30
31
}

32
33
namespace detail {

34
at::Tensor _roi_align_backward(
35
36
    const at::Tensor& grad,
    const at::Tensor& rois,
37
38
39
40
41
42
43
44
45
    double spatial_scale,
    int64_t pooled_height,
    int64_t pooled_width,
    int64_t batch_size,
    int64_t channels,
    int64_t height,
    int64_t width,
    int64_t sampling_ratio,
    bool aligned) {
46
47
48
49
50
  static auto op =
      c10::Dispatcher::singleton()
          .findSchemaOrThrow("torchvision::_roi_align_backward", "")
          .typed<decltype(_roi_align_backward)>();
  return op.call(
51
52
53
54
55
56
57
58
59
      grad,
      rois,
      spatial_scale,
      pooled_height,
      pooled_width,
      batch_size,
      channels,
      height,
      width,
AhnDW's avatar
AhnDW committed
60
61
      sampling_ratio,
      aligned);
62
}
63

64
65
} // namespace detail

66
67
68
69
70
71
72
TORCH_LIBRARY_FRAGMENT(torchvision, m) {
  m.def(
      "roi_align(Tensor input, Tensor rois, float spatial_scale, int pooled_height, int pooled_width, int sampling_ratio, bool aligned) -> Tensor");
  m.def(
      "_roi_align_backward(Tensor grad, Tensor rois, float spatial_scale, int pooled_height, int pooled_width, int batch_size, int channels, int height, int width, int sampling_ratio, bool aligned) -> Tensor");
}

73
74
} // namespace ops
} // namespace vision