Back Home

GitHub Repo

Transformers Community Reports GOT-OCR2 Coordinate Mismatch; NumPy Images May Change Region Recognition Input

A Transformers community report on October 23 says GOT-OCR2 may produce incorrect region coordinates when processing NumPy images because of inconsistent width–height ordering. The report includes a CPU-only reproduction, but the impact on released versions and the fix status remain unconfirmed.

Marcus Qwertyus · Public domain · Image source
zh-Hant

On October 23, a Transformers community member reported a GOT-OCR2 preprocessing bug: the same image and recognition-region coordinates may produce different model inputs depending on whether the image is passed as a PIL image or a NumPy array. The report uses Transformers 5.21.0.dev0 and can be reproduced on a CPU without downloading model weights. The public issue page does not yet show maintainer confirmation. Issue report

The reporter traced the cause to a mismatch in the size conventions used by two functions. get_image_size() returns width, height for PIL images but height, width for NumPy arrays, while preprocess_box_annotation() always interprets its input as width, height. According to the reporter’s source-code analysis, both the single-image and multipage processing paths pass this size result through directly, causing subsequent coordinate normalization to use the wrong denominators. Technical details

In the reported example, an image is 320 pixels wide and 120 pixels high, with the box [32,12,160,60]. The PIL path yields normalized coordinates [100,100,500,500], while the NumPy path yields [266,37,1333,187], with one value exceeding the expected range of zero to one thousand. The reporter also says a comparison of the actual processor inputs found fourteen mismatched token IDs. This test shows that the difference reaches the model prompt, but the error rate for final recognition text has not been measured. Reproduction results

This has direct relevance for document extraction workflows. The official documentation allows users to specify pixel coordinates with box=[x1,y1,x2,y2] to direct GOT-OCR2 to recognize a particular region. If an image pipeline changes its image representation and thereby changes the coordinate prompt, engineers could mistake a preprocessing difference for model recognition instability. This is a risk inferred from the interface’s intended use, not a verified downstream incident. Official region recognition documentation

Teams using this feature can first compare normalized coordinates and input tokens across the PIL and NumPy paths with non-square images, then decide whether to standardize temporarily on PIL. They should track whether a fix covers both single-image and multipage paths, and which released versions are affected. Current evidence is insufficient to extend the issue to all GOT-OCR2 tasks or model weights.

Sources

  1. GOT-OCR2 produces incorrect bounding-box coordinates for NumPy images · Issue #49902
  2. GOT-OCR2 — Transformers documentation