vision.cpp 1.17 KB
Newer Older
1
2
3
4
5
6
7
#include <Python.h>
#include <torch/script.h>

#ifdef WITH_CUDA
#include <cuda.h>
#endif

8
9
#include "PSROIAlign.h"
#include "PSROIPool.h"
10
11
12
13
#include "ROIAlign.h"
#include "ROIPool.h"
#include "nms.h"

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension
#ifdef _WIN32
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_custom_ops(void) {
  // No need to do anything.
  // _custom_ops.py will run on load
  return NULL;
}
#else
PyMODINIT_FUNC PyInit__custom_ops(void) {
  // No need to do anything.
  // _custom_ops.py will run on load
  return NULL;
}
#endif
30
31
#endif

32
int64_t _cuda_version() {
33
#ifdef WITH_CUDA
34
35
36
  return CUDA_VERSION;
#else
  return -1;
37
#endif
38
}
39
40
41
42
43
44
45

static auto registry =
    torch::RegisterOperators()
        .op("torchvision::nms", &nms)
        .op("torchvision::roi_align(Tensor input, Tensor rois, float spatial_scale, int pooled_height, int pooled_width, int sampling_ratio) -> Tensor",
            &roi_align)
        .op("torchvision::roi_pool", &roi_pool)
46
47
        .op("torchvision::ps_roi_align", &ps_roi_align)
        .op("torchvision::ps_roi_pool", &ps_roi_pool)
48
        .op("torchvision::_cuda_version", &_cuda_version);