ps_roi_align.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "ps_roi_align.h"
  2. #include <ATen/core/dispatch/Dispatcher.h>
  3. #include <torch/library.h>
  4. #include <torch/types.h>
  5. namespace vision {
  6. namespace ops {
  7. std::tuple<at::Tensor, at::Tensor> ps_roi_align(
  8. const at::Tensor& input,
  9. const at::Tensor& rois,
  10. double spatial_scale,
  11. int64_t pooled_height,
  12. int64_t pooled_width,
  13. int64_t sampling_ratio) {
  14. C10_LOG_API_USAGE_ONCE("torchvision.csrc.ops.ps_roi_align.ps_roi_align");
  15. static auto op = c10::Dispatcher::singleton()
  16. .findSchemaOrThrow("torchvision::ps_roi_align", "")
  17. .typed<decltype(ps_roi_align)>();
  18. return op.call(
  19. input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio);
  20. }
  21. namespace detail {
  22. at::Tensor _ps_roi_align_backward(
  23. const at::Tensor& grad,
  24. const at::Tensor& rois,
  25. const at::Tensor& channel_mapping,
  26. double spatial_scale,
  27. int64_t pooled_height,
  28. int64_t pooled_width,
  29. int64_t sampling_ratio,
  30. int64_t batch_size,
  31. int64_t channels,
  32. int64_t height,
  33. int64_t width) {
  34. static auto op =
  35. c10::Dispatcher::singleton()
  36. .findSchemaOrThrow("torchvision::_ps_roi_align_backward", "")
  37. .typed<decltype(_ps_roi_align_backward)>();
  38. return op.call(
  39. grad,
  40. rois,
  41. channel_mapping,
  42. spatial_scale,
  43. pooled_height,
  44. pooled_width,
  45. sampling_ratio,
  46. batch_size,
  47. channels,
  48. height,
  49. width);
  50. }
  51. } // namespace detail
  52. TORCH_LIBRARY_FRAGMENT(torchvision, m) {
  53. m.def(TORCH_SELECTIVE_SCHEMA(
  54. "torchvision::ps_roi_align(Tensor input, Tensor rois, float spatial_scale, int pooled_height, int pooled_width, int sampling_ratio) -> (Tensor, Tensor)"));
  55. m.def(TORCH_SELECTIVE_SCHEMA(
  56. "torchvision::_ps_roi_align_backward(Tensor grad, Tensor rois, Tensor channel_mapping, float spatial_scale, int pooled_height, int pooled_width, int sampling_ratio, int batch_size, int channels, int height, int width) -> Tensor"));
  57. }
  58. } // namespace ops
  59. } // namespace vision