Copy GpuMat to CUDA Tensor
I am trying to run model inference in C++.
I succesfully traced model in Python with torch.jit.trace.
I am able to load model in C++ using torch::jit::load().
I was able to perform inference both on cpu and gpu, however the starting point was always torch::from_blob method which seems to be creating cpu-side tensor.
For efficiency, I would like to cast/copy cv::cuda::GpuMat directly to CUDA Tensor. I have been digging through pytorch tests and docs in search of convinient example, but was unable to find one.

Question:
How to create CUDA Tensor from cv::cuda::GpuMat?

Here is an example:

//define the deleter ...
void deleter(void* arg) {};

//your convert function 

cuda::GpuMat gImage;

//build or load your image here ...

std::vector&lt;int64_t&gt; sizes = {1, static_cast&lt;int64_t&gt;(gImage.channels()),
                          static_cast&lt;int64_t&gt;(gImage.rows),
                          static_cast&lt;int64_t&gt;(gImage.cols)};

long long step = gImage.step / sizeof(float);

std::vector&lt;int64_t&gt; strides = {1, 1, step, static_cast&lt;int64_t&gt;(gImage.channels())};

auto tensor_image = torch::from_blob(gImage.data, sizes, strides, deleter,  torch::kCUDA);
std::cout &lt;&lt; "output tensor image : " &lt;&lt; tensor_image &lt;&lt; std::endl;

