Skip to content

Conversation

@AntoineSimoulin
Copy link
Member

@AntoineSimoulin AntoineSimoulin commented Nov 6, 2025

Summary

Users have to explicitly opt-in for those transforms. Here we provide the first building block for this interface. We add the functionals to_nvcv_image and nvcv_to_tensor to transform torch.Tensor to nvcv.Tensor. We also implement the corresponding class transforms ToNVCVImage and NVCVToTensor.

How to use

from PIL import Image
import torchvision.transforms.v2.functional as F

orig_img = Image.open("leaning_tower.jpg")
img_tensor = F.pil_to_tensor(orig_img)
nvcv_tensor = F.to_nvcv_tensor(img_tensor.cuda())
img_tensor = F.nvcv_to_tensor(nvcv_tensor)

Note

NVCV tensors are automatically converted to NHWC format. Contrary to torchvision convention, which relies on NCHW format.

Run unit tests

pytest test/test_cvcuda.py
...
37 passed in 0.15s

Differential Revision: D85862362

Summary:
Users have to explicitly opt-in for those transforms. Here we provide the first building block for this interface. We add the functionals `to_nvcv_image` and `nvcv_to_tensor` to transform `torch.Tensor` to `nvcv.Tensor`. We also implement the corresponding class transforms `ToNVCVImage` and `NVCVToTensor`.

## How to use

```python
from PIL import Image
import torchvision.transforms.v2.functional as F

orig_img = Image.open("leaning_tower.jpg")
img_tensor = F.pil_to_tensor(orig_img)
nvcv_tensor = F.to_nvcv_tensor(img_tensor.cuda())
img_tensor = F.nvcv_to_tensor(nvcv_tensor)
```

NOTE: NVCV tensors are automatically converted to NHWC format. Contrary to torchvision convention, which relies on NCHW format.

Differential Revision: D85862362
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 6, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9259

Note: Links to docs will display an error until the docs builds have been completed.

❌ 9 New Failures

As of commit e96659c with merge base 2fee489 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the cla signed label Nov 6, 2025
@meta-codesync
Copy link

meta-codesync bot commented Nov 6, 2025

@AntoineSimoulin has exported this pull request. If you are a Meta employee, you can view the originating Diff in D85862362.

@AntoineSimoulin
Copy link
Member Author

NOTES:

  • Should we upload tensors .to(cuda) directly inside to_nvcv_tensor function?
  • Should we keep CVCUDA specific functions inside isolated "_cvcuda" files or within existing files (e.g. "_geometry")?
  • NVCV tensors are automatically converted to NHWC format. Contrary to torchvision convention, which relies on NCHW format. If we call to_nvcv_tensor and then nvcv_to_tensor, we might have an output tensor with a different shape.
  • Are the image format from _infer_nvcv_format exhaustive and aligned with what is done for PIL?
  • What is the difference between nvcv.Image and nvcv.Tensor?

@meta-codesync
Copy link

meta-codesync bot commented Nov 7, 2025

@AntoineSimoulin has imported this pull request. If you are a Meta employee, you can view this in D85862362.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant