FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add support for sensor_msgs/Image in torch_conversions by nvcyc · Pull Request #17 · ros2/rosidl_buffer_backends · GitHub

Repository navigation

Add support for sensor_msgs/Image in torch_conversions - #17

Open
nvcyc wants to merge 1 commit into
mainfrom
nvcyc/torch_conversion_image
Open

nvcyc wants to merge 1 commit into
mainfrom
nvcyc/torch_conversion_image

Conversation

nvcyc commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL