vision.cpp 1.02 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
10
11
#include "ROIAlign.h"
#include "ROIPool.h"
#include "nms.h"

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 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
28
29
#endif

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

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)
        .op("torchvision::_cuda_version", &_cuda_version);