[QUESTION] How to Convert a CV-CUDA Tensor to numpy array and pycuda tensor without `torch.as_tensor`
While using CV-CUDA for GPU acceleration, a notable limitation is the absence of a direct conversion method from CV-CUDA tensor to PyTorch Tensor or PyCUDA GPUArray. While cvcuda.as_tensor facilitates the conversion from PyTorch Tensor or PyCUDA GPUArray to CV-CUDA tensor, a direct reverse conversion is not readily available. Additionally, converting to a NumPy array typically involves using torch.as_tensor followed by .cpu().numpy().
While studying the CV-CUDA source code it seems that the primary conversion method involves using torch.as_tensor. Is there an alternative conversion approach that doesn't rely on torch.as_tensor and enables direct conversion of a CV-CUDA tensor to PyCUDA GPUArray and NumPy array?
Before read this question.
I use sth like this I found in tests . I change numpy to CV-CUDA tensor with cupy.
mean = (0.485, 0.456, 0.406)
std = (0.229, 0.224, 0.225)
resize = 1024
crop_size = 320
mean_cp = cp.asarray(mean, dtype=cp.float32).reshape(1, 1, 3)
std_cp = cp.asarray(std, dtype=cp.float32).reshape(1, 1, 3)
mean_tensor = cvcuda.as_tensor(mean_cp, nvcv.TensorLayout.HWC)
std_tensor = cvcuda.as_tensor(std_cp, nvcv.TensorLayout.HWC)
cv_tensor = cvcuda.reformat(cv_tensor, nvcv.TensorLayout.CHW, stream=stream)
cv_img = cp.asarray(cv_tensor.cuda())[None]
return cv_img.get()
But I also want to get a native and fastest function to do that.