roi_pool.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "roi_pool.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> roi_pool(
  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. C10_LOG_API_USAGE_ONCE("torchvision.csrc.ops.roi_pool.roi_pool");
  14. static auto op = c10::Dispatcher::singleton()
  15. .findSchemaOrThrow("torchvision::roi_pool", "")
  16. .typed<decltype(roi_pool)>();
  17. return op.call(input, rois, spatial_scale, pooled_height, pooled_width);
  18. }
  19. namespace detail {
  20. at::Tensor _roi_pool_backward(
  21. const at::Tensor& grad,
  22. const at::Tensor& rois,
  23. const at::Tensor& argmax,
  24. double spatial_scale,
  25. int64_t pooled_height,
  26. int64_t pooled_width,
  27. int64_t batch_size,
  28. int64_t channels,
  29. int64_t height,
  30. int64_t width) {
  31. static auto op = c10::Dispatcher::singleton()
  32. .findSchemaOrThrow("torchvision::_roi_pool_backward", "")
  33. .typed<decltype(_roi_pool_backward)>();
  34. return op.call(
  35. grad,
  36. rois,
  37. argmax,
  38. spatial_scale,
  39. pooled_height,
  40. pooled_width,
  41. batch_size,
  42. channels,
  43. height,
  44. width);
  45. }
  46. } // namespace detail
  47. TORCH_LIBRARY_FRAGMENT(torchvision, m) {
  48. m.def(TORCH_SELECTIVE_SCHEMA(
  49. "torchvision::roi_pool(Tensor input, Tensor rois, float spatial_scale, int pooled_height, int pooled_width) -> (Tensor, Tensor)"));
  50. m.def(TORCH_SELECTIVE_SCHEMA(
  51. "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"));
  52. }
  53. } // namespace ops
  54. } // namespace vision