Вот пример:
//define the deleter ...
void deleter(void* arg) {};
//your convert function
cuda::GpuMat gImage;
//build or load your image here ...
std::vector<int64_t> sizes = {1, static_cast<int64_t>(gImage.channels()),
static_cast<int64_t>(gImage.rows),
static_cast<int64_t>(gImage.cols)};
long long step = gImage.step / sizeof(float);
std::vector<int64_t> strides = {1, 1, step, static_cast<int64_t>(gImage.channels())};
auto tensor_image = torch::from_blob(gImage.data, sizes, strides, deleter, torch::kCUDA);
std::cout << "output tensor image : " << tensor_image << std::endl;