Add native sensor_msgs/msg/Image support to torch_conversions library.
This change introduces APIs to:
Allocate initialized CPU- or CUDA-backed image messages.
Create writable HWC tensor views over image buffers.
Create cloned or zero-copy HWC tensor views from received images.
Copy tensors into existing image messages while preserving headers and image metadata.
Allocate and populate image messages directly from HWC tensors.
Preserve row padding through tensor strides.
The conversion path maintains CUDA buffer lifetime and stream-event ordering without introducing device or stream synchronization. It supports packed, byte-oriented encodings and validates encodings,
buffer sizes, row strides, tensor shapes, and data types.
Is this user-facing behavior change?
Yes. Users can now convert native ROS sensor_msgs/msg/Image messages directly to and from PyTorch at::Tensor objects.
Images are represented as HWC tensors. Zero-copy input views are available by passing clone=false.
Did you use Generative AI?
OpenAI Codex (GPT-5) was used to draft the changes in this pull request.
Additional Information
The current implementation supports packed, 8-bit-per-channel encodings, including mono8, rgb8, bgr8, rgba8, Bayer8, YUV422, and 8UC/8SC encodings. Planar and non-byte encodings are rejected
with descriptive errors.
For zero-copy CPU input views, the source message must remain alive while the tensor is in use. CUDA views retain the appropriate buffer handles and stream-event dependencies for the tensor lifetime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add native sensor_msgs/msg/Image support to torch_conversions library.
This change introduces APIs to:
The conversion path maintains CUDA buffer lifetime and stream-event ordering without introducing device or stream synchronization. It supports packed, byte-oriented encodings and validates encodings,
buffer sizes, row strides, tensor shapes, and data types.
Is this user-facing behavior change?
Yes. Users can now convert native ROS sensor_msgs/msg/Image messages directly to and from PyTorch at::Tensor objects.
Images are represented as HWC tensors. Zero-copy input views are available by passing clone=false.
Did you use Generative AI?
OpenAI Codex (GPT-5) was used to draft the changes in this pull request.
Additional Information
The current implementation supports packed, 8-bit-per-channel encodings, including mono8, rgb8, bgr8, rgba8, Bayer8, YUV422, and 8UC/8SC encodings. Planar and non-byte encodings are rejected
with descriptive errors.
For zero-copy CPU input views, the source message must remain alive while the tensor is in use. CUDA views retain the appropriate buffer handles and stream-event dependencies for the tensor lifetime.