Hello,
I made a small test program :
import numpy as np
import cv2
import vpi
Image_Test = ‘/home/alain/Work/Python/Pytorch/Images/4K_base.tif’
Save_image_vpi = ‘/home/alain/Work/Python/Pytorch/Images/4K_result_VPI.jpg’
img_OpenCV = cv2.imread(Image_Test,cv2.IMREAD_COLOR)
img_OpenCV_mono = cv2.cvtColor(img_OpenCV,cv2.COLOR_BGR2GRAY)
niveau_blur = 11
backend = vpi.Backend.CUDA
with backend:
image_vpi = vpi.asimage(img_OpenCV_mono)
gaussian = image_vpi.gaussian_filter(niveau_blur, 1.7, border=vpi.Border.ZERO)
image_gaussian_blur_mono = gaussian.cpu()
cv2.imwrite(Save_image_vpi, image_gaussian_blur_mono, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
In that case (i only import VPI library), the test is OK.
I made an other test : this time, i also import Pycuda to be more close than my software JetsonSky.
import numpy as np
import cv2
import vpi
import pycuda.driver as drv
import pycuda.autoinit
from pycuda.compiler import SourceModule
import pycuda.cumath
Image_Test = ‘/home/alain/Work/Python/Pytorch/Images/4K_base.tif’
Save_image_vpi = ‘/home/alain/Work/Python/Pytorch/Images/4K_result_VPI.jpg’
img_OpenCV = cv2.imread(Image_Test,cv2.IMREAD_COLOR)
img_OpenCV_mono = cv2.cvtColor(img_OpenCV,cv2.COLOR_BGR2GRAY)
niveau_blur = 11
backend = vpi.Backend.CUDA
with backend:
image_vpi = vpi.asimage(img_OpenCV_mono)
gaussian = image_vpi.gaussian_filter(niveau_blur, 1.7, border=vpi.Border.ZERO)
image_gaussian_blur_mono = gaussian.cpu()
cv2.imwrite(Save_image_vpi, image_gaussian_blur_mono, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
In that case, i have this error :
Traceback (most recent call last):
File “/usr/lib/python3.8/idlelib/run.py”, line 559, in runcode
exec(code, self.locals)
File “/home/alain/Work/Python/Pytorch/testVPI.py”, line 23, in
image_gaussian_blur_mono = gaussian.cpu()
RuntimeError: VPI_ERROR_INTERNAL: (cudaErrorDeviceUninitialized)
In my software JetsonSky, here is my code for GaussianBlur_Mono (it’s a function) :
def gaussianblur_mono(image_mono,niveau_blur):
global compute_library
image_gaussian_blur_mono = image_mono
if compute_library == "opencv" :
image_gaussian_blur_mono = cv2.GaussianBlur(image_mono,(niveau_blur,niveau_blur),cv2.BORDER_DEFAULT)
if compute_library == "vpi" :
if niveau_blur > 11 :
niveau_blur = 11
backend = vpi.Backend.CUDA
with backend:
image_vpi = vpi.asimage(image_mono)
gaussian = image_vpi.gaussian_filter(niveau_blur, 1.7, border=vpi.Border.ZERO)
image_gaussian_blur_mono = gaussian.cpu()
return image_gaussian_blur_mono
When i call this function, i get this error :
Exception in Tkinter callback
Traceback (most recent call last):
File “/usr/lib/python3.8/tkinter/init.py”, line 1892, in call
return self.func(*args)
File “/usr/lib/python3.8/tkinter/init.py”, line 814, in callit
func(*args)
File “/home/alain/Work/Python/JetsonSky/JetsonSky_V16_03Base.py”, line 2270, in refresh
application_filtrage()
File “/home/alain/Work/Python/JetsonSky/JetsonSky_V16_03Base.py”, line 3299, in application_filtrage
fd_b=gaussianblur_mono(fd_b,niveau_blur)
File “/home/alain/Work/Python/JetsonSky/JetsonSky_V16_03Base.py”, line 2540, in gaussianblur_mono
image_gaussian_blur_mono = gaussian.cpu()
RuntimeError: VPI_ERROR_INTERNAL: Can’t perform shared mapping
It seems VPI doesn’t like Pycuda very much.
It would be really useful if we could use VPI with Pycuda (same thing with Cupy and Pycuda).
Alain