Rockchip · AI & Linux Hub

AI inference

When a Rockchip NPU predicts the same class: test RGB order and tensor layout

Treating BGR read by OpenCV as RGB and interpreting NHWC memory as NCHW may produce tensors with correct size but wrong meaning.

The model therefore runs successfully but repeatedly gives strange classifications. By first verifying the preprocessing with input that can be calculated by hand, it is easier to find the cause than by observing real photos.

Construct an asymmetric input

Make a test picture with red on the left and blue on the right, and add a small green block in one corner. Save the actual bytes or statistics before feeding into the model. If the order of channels in the red area is wrong, check the color conversion first. If the colors are repeatedly misaligned along the entire row, check the dimension order and step size again.

Verification normalization is only done once

List the initial range of pixels, the locations of subtraction and scaling, and whether equivalent processing has been configured during tool chain conversion. Repeated execution of the same process on the application and model front ends will cause scope exceptions. Compare the specific value of a red pixel at each step without running the entire data set first.

Return to the real task

The test chart is used to verify the data channel and is not responsible for model accuracy evaluation. After correction, use a labeled small sample to compare the original frame and plate end results, and save this probe map in the application regression to prevent color errors from being reintroduced when the reading library is replaced.

The reference value of a piece of red probe

stage Example of single pixel in red area
8-bit RGB Red 255 Green 0 Blue 0
8-bit BGR Blue 0 Green 0 Red 255
RGB divided only by 255 Red 1.0 Green 0 Blue 0

Board documentation and references

ArmSoM Sige7

Products and development resources

Check the hardware revision, carrier, image and interfaces in the product documentation. An article association is not evidence that a configuration has been tested.

Explore this topic → · Learning paths →