Jump to content

BgraToPlanarTensorOp

From RidgeRun Developer Wiki

🚧 Documentation is under development

The Holoscan SDK guide is currently under active development. Some sections may be incomplete or change without notice.

Questions? Contact RidgeRun or email to support@ridgerun.com.

Contents Pin






Preliminary reference
This reference is preliminary. The set of available operators and HSDK applications, along with their APIs and documented behavior, may change in future releases.


BgraToPlanarTensorOp

BgraToPlanarTensorOp converts a CUDA-resident BGRA image into a normalized planar RGB tensor for a vision model. The implementation is part of the RidgeRun Holoscan 5 module and runs the resize, channel reorder and normalization kernel on the execution stream.


CUDA preprocessing
For help matching image size, channel order, and normalization to your model, contact RidgeRun about custom CUDA preprocessing.


Input arguments

Construct the operator with the source image dimensions, network dimensions and per-channel normalization values:

Argument Default and meaning
source_width, source_height Required dimensions of the contiguous BGRA input image.
network_width, network_height 518 × 518 by default; dimensions of the model input.
mean RGB mean values {0.485, 0.456, 0.406} by default.
standard_deviation RGB standard deviations {0.229, 0.224, 0.225} by default. Every value must be finite and positive.

All dimensions must be positive. The operator validates the byte bounds before the graph is compiled.

Ports and data contract

Port Memory Queue Trigger Contract
input CUDA device, contiguous SDK default OnEach U8 rank-3 tensor with shape [source_height, source_width, 4] in BGRA order.
output CUDA device, runtime pool N/A Same activation F32 rank-4 tensor with shape [1, 3, network_height, network_width] in planar RGB order.

The output uses runtime-pool storage and preserves the input sample metadata. A CUDA stream must be available in the execution context.

Preprocessing

The CUDA kernel maps each network pixel to the source image with integer coordinate sampling. It reads the BGRA bytes, converts the channel order to RGB, scales each channel to [0,1], and applies (value - mean) / standard_deviation. It does not add letterbox padding; callers that require aspect-ratio preservation must perform that step separately or use RawBayerToYoloTensorOp.

Build

Follow Holoscan RidgeRun Build and Installation for the module build and installation. The operator-specific include, target, and runtime requirements are listed below.

Include bgra_to_planar_tensor/bgra_to_planar_tensor.hpp and link holoscan::bgra_to_planar_tensor.

Example

The source image dimensions are fixed when the operator is constructed. Bind the output to the CUDA device before compiling the graph when it is consumed by a device-side inference operator:

auto preprocess = graph.op<BgraToPlanarTensorOp>(
    "preprocess", 1920, 1080, 518, 518,
    std::array<float, 3>{0.485F, 0.456F, 0.406F},
    std::array<float, 3>{0.229F, 0.224F, 0.225F});
graph.add_flow(camera->frame, preprocess->input);

compile_options.deployment.bind_tensor_output_device(
    holoscan::TensorOutputDevicePlacement{
        .operator_path = "preprocess",
        .output_port = "output",
        .device = holoscan::DeviceId{0}});

The implementation uses integer source-coordinate sampling: each output pixel selects the corresponding BGRA source pixel after scaling. It does not preserve aspect ratio or add letterbox padding. Use RawBayerToYoloTensorOp when the model path needs fused aspect-ratio-preserving letterboxing from RG10.


Source reference
You can find the source code at BgraToPlanarTensorOp.


Related pages


Cookies help us deliver our services. By using our services, you agree to our use of cookies.