NVIDIA / NVIDIA/TensorRT-Edge-LLM

stbir_resize in resizeImage maybe calc wrong result

Open Beginner friendly
#116 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
563
Forks
135
Avg merge
14h 13m
Merged PRs (30d)
1

Description

stbir_resize in resizeImage maybe calc wrong result

https://github.com/NVIDIA/TensorRT-Edge-LLM/blob/release/0.8.0/cpp/multimodal/qwenViTRunner.cpp#L438-L449

            if (doResize)
            {
                auto [resizedHeight, resizedWidth] = getResizedImageSize(image.height, image.width);
                rt::imageUtils::resizeImage(
                    image, mResizedImageHost, resizedWidth, resizedHeight, rt::imageUtils::InterpolationMode::kBICUBIC);
                formatPatch(mResizedImageHost, imageGridTHWs, imageTokenLengths, cuSeqlensData, cuSeqlensSize,
                    maxSeqLen, stream);
            }
            else
            {
                formatPatch(image, imageGridTHWs, imageTokenLengths, cuSeqlensData, cuSeqlensSize, maxSeqLen, stream);
            }

when image.height == resizedHeight && image.width == resizedWidth, it still enter
into resizeImage function, https://github.com/NVIDIA/TensorRT-Edge-LLM/blob/release/0.8.0/cpp/runtime/imageUtils.cpp#L104-L127


    if (mode == InterpolationMode::kBICUBIC)
    {
        stbir_resize(image.data(), image.width, image.height, kINPUT_STRIDE_BYTES, resizedImage.data(), newWidth,
            newHeight, kOUTPUT_STRIDE_BYTES, STBIR_RGB, STBIR_TYPE_UINT8, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM);
    }

it will generate wrong/unstable output even if each input is fixed, the STBIR_FILTER_CATMULLROM mode can cause data fluctuations.


So how to fix ?
ref follow :

            if (doResize)
            {
                auto [resizedHeight, resizedWidth] = getResizedImageSize(image.height, image.width);
               if (resizedHeight != image.height || resizedWidth != image.width) {
                    rt::imageUtils::resizeImage(
                        image, mResizedImageHost, resizedWidth, resizedHeight, rt::imageUtils::InterpolationMode::kBICUBIC);
                    formatPatch(mResizedImageHost, imageGridTHWs, imageTokenLengths, cuSeqlensData, cuSeqlensSize,
                        maxSeqLen, stream);
                }
                else {
                    formatPatch(image, imageGridTHWs, imageTokenLengths, cuSeqlensData, cuSeqlensSize, maxSeqLen, stream);
                }
            }
            else
            {
                formatPatch(image, imageGridTHWs, imageTokenLengths, cuSeqlensData, cuSeqlensSize, maxSeqLen, stream);
            }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cpp/multimodal/qwenViTRunner.cpp around the resizeImage call, then inspect cpp/runtime/imageUtils.cpp and its STBIR path. Ensure equal input and target dimensions do not go through the bicubic resize, while other cases retain the existing flow; done means the original image is formatted when dimensions match and resized output is used otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-vision
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.