Python GPU Retrieval Examples Request

I’m excited to leverage the ability to keep camera data on the GPU when using the python API.

Added CUDA stream input to Camera::retrieveImage and Camera::retrieveMeasure for improved performance in GPU asynchronous workflows.
Added GPU-optimized functions, blobFromImage, and blobFromImages, for converting images to Deep Learning model tensor inputs.
Added utility functions, Mat::convertColor, for common color conversions, such as swapping red and blue channels and removing the alpha channel.

Can you please provide a python example of getting the data into a CuPy array and ideally a pytorch tensor while keeping the data on GPU?

Related: Will the api reference docs be updated with 5.0 information soon?

This is still an experimental feature. Examples and full API documentation will be available soon.

Sounds good. For now I’ll proceed with using

bgr_mat = sl.Mat(res.width, res.height, sl.MAT_TYPE.U8_C4)
zed.retrieve_image(
                bgr_mat,
                sl.VIEW.LEFT,
                sl.MEM.GPU,
                sl.Resolution(res.width, res.height),
 )
torch.as_tensor(bgr_mat.get_data(sl.MEM.GPU), device='cuda'))

Hi @robots,

Thanks for the interest with the GPU retrieval!

We are currently updating our sample to showcase CuPy usage (and the performance gains it brings). It should be available in a following release.

In the meantime, your plan sounds good !

If working with a runtime critical environment, an alternative would be to use torch.from_dlpack(cupy_arr.toDlpack()) instead of torch.as_tensor(cupy_arr, device='cuda')) to profit from zero-copy data exchange (see Interoperability — CuPy 13.5.1 documentation for more info)


If while using CuPy, you faced any difficulties or anything you’d like to share, we’d be happy to adapt our docs in consequence.

1 Like