roi_pool.cpp 1.81 KB
Newer Older
1
#include "roi_pool.h"
2

3
4
#include <ATen/core/dispatch/Dispatcher.h>
#include <torch/library.h>
5
#include <torch/types.h>
6

7
8
namespace vision {
namespace ops {
9
10

std::tuple<at::Tensor, at::Tensor> roi_pool(
11
12
    const at::Tensor& input,
    const at::Tensor& rois,
13
14
15
    double spatial_scale,
    int64_t pooled_height,
    int64_t pooled_width) {
Kai Zhang's avatar
Kai Zhang committed
16
  C10_LOG_API_USAGE_ONCE("torchvision.csrc.ops.roi_pool.roi_pool");
17
18
19
20
21
22
  static auto op = c10::Dispatcher::singleton()
                       .findSchemaOrThrow("torchvision::roi_pool", "")
                       .typed<decltype(roi_pool)>();
  return op.call(input, rois, spatial_scale, pooled_height, pooled_width);
}

23
24
namespace detail {

25
at::Tensor _roi_pool_backward(
26
27
28
    const at::Tensor& grad,
    const at::Tensor& rois,
    const at::Tensor& argmax,
29
30
31
32
33
34
35
36
37
38
39
    double spatial_scale,
    int64_t pooled_height,
    int64_t pooled_width,
    int64_t batch_size,
    int64_t channels,
    int64_t height,
    int64_t width) {
  static auto op = c10::Dispatcher::singleton()
                       .findSchemaOrThrow("torchvision::_roi_pool_backward", "")
                       .typed<decltype(_roi_pool_backward)>();
  return op.call(
40
41
42
43
44
45
46
47
48
49
      grad,
      rois,
      argmax,
      spatial_scale,
      pooled_height,
      pooled_width,
      batch_size,
      channels,
      height,
      width);
50
51
}

52
53
} // namespace detail

54
TORCH_LIBRARY_FRAGMENT(torchvision, m) {
55
56
57
58
  m.def(TORCH_SELECTIVE_SCHEMA(
      "torchvision::roi_pool(Tensor input, Tensor rois, float spatial_scale, int pooled_height, int pooled_width) -> (Tensor, Tensor)"));
  m.def(TORCH_SELECTIVE_SCHEMA(
      "torchvision::_roi_pool_backward(Tensor grad, Tensor rois, Tensor argmax, float spatial_scale, int pooled_height, int pooled_width, int batch_size, int channels, int height, int width) -> Tensor"));
59
60
}

61
62
} // namespace ops
} // namespace vision