- TextRecognizer.get_character_dict saved the downloaded character dict to
the package models dir even when Global.model_root_dir was set, which
fails with PermissionError on a read-only install. Save it under
model_root_dir when set; fall back to DEFAULT_MODEL_PATH otherwise.
- The torch ModelLoader used cfg.model_root_dir / ... without Path(), so a
str model_root_dir raised TypeError. Wrap it in Path() like the other
engines do.
- Add tests that need no model download.
TextDetector.get_preprocess replaced limit_side_len with a hard-coded
960/1500/2000 bucket whenever limit_type was "max", so the configured
value was ignored and large images reached the detector unresized.
Pass the configured limit_side_len through for both limit types, matching
PaddleOCR DetResizeForTest.
Transformer.forward_train calls
tgt_mask = self.generate_square_subsequent_mask(tgt.shape[0], tgt.device)
but the helper only accepts sz, so the training branch of
Transformer.forward raises
TypeError: Transformer.generate_square_subsequent_mask() takes 2
positional arguments but 3 were given
The other two call sites (forward_test and forward_beam) pass one
argument and are unaffected.
Accept an optional device and forward it to the two tensor
constructors. It defaults to None, so the one-argument call sites keep
building the mask on the CPU exactly as before, and the call site that
already asks for a device now gets one.
Concurrent first calls could initialize det/cls/rec more than once. Double-check each loader under its own lock.
Fixes#724
Co-authored-by: Yuzhong Zhang <BetterAndBetterII@users.noreply.github.com>
MNNInferSession.__call__ extracted session output via
np.array(out_tensor.getData()).reshape(out_shape), which marshals
tensor contents through a slow per-element Python path. For a
PP-OCRv6 medium recognizer output (~17MB), this cost ~454ms versus
~210ms for the actual GPU inference that produced it.
Switch to getNumpyData(), which exposes the buffer directly. An
explicit copy is required since getNumpyData() returns a view into
memory owned by out_tensor; without it, out_tensor going out of
scope or being reused across shape changes caused intermittent
segfaults.
On a 39-box real-world image, total recognition time dropped from
~22s to ~8.4s. Per-crop output extraction dropped from ~454ms to
~10ms.
Fixes intermittent segfault risk from unmanaged zero-copy tensor
lifetime as a side effect.
* feat(python): support PP-OCRv6 for onnxruntime and openvino
Add PP-OCRv6 rec and det models (tiny/small/medium) for onnxruntime and openvino engines. v6 ships no cls model; reuse PP-OCRv5 cls.
- typings.py: add OCRVersion.PPOCRV6 and ModelType.TINY/SMALL/MEDIUM
- default_models.yaml: add PP-OCRv6 blocks under onnxruntime/openvino with PaddlePaddle official ModelScope URLs, verified SHA256, and dict_url (PaddleOCR dict files)
Verified end-to-end on ch_en_num.jpg with v6 small det+rec + v5 cls (onnxruntime): 18 text lines recognized correctly.
* fix(python): use uniquely-named PP-OCRv6 model URLs to avoid cache collision
PP-OCRv6 official ONNX exports are all named inference.onnx, causing det and rec models to overwrite each other in RapidOCR's cache (cache_dir/Path(url).name). Switch model_dir/dict_url to a mirror with unique filenames (ch_PP-OCRv6_<task>_<size>.onnx) under modelscope.cn/models/jaminmei/PP-OCRv6-onnx@v1.0. SHA256 unchanged (byte-identical files, renamed only).
Verified onnxruntime + openvino: no more redownload-on-collision; second run is pure cache hit.
* test(python): add PP-OCRv6 det/rec unit tests for onnxruntime and openvino
Mirror the test_ppocrv5_det/rec_mobile pattern. v6 small det on ch_en_num.jpg -> 18 boxes; v6 small rec on text_rec.jpg -> '韩国小馆'. Parametrized over the two engines v6 supports (ONNXRUNTIME, OPENVINO). Existing 100 tests unaffected (verified via collect-only).
Verified: 4 new tests pass (onnxruntime + openvino x det/rec).
* chore(python): switch PP-OCRv6 model URLs to official RapidAI/RapidOCR repo
- det/rec x tiny/small/medium now point to modelscope.cn/RapidAI/RapidOCR (official SWHL conversion, not contributor mirror)
- update SHA256 to the official files' hashes
- drop rec dict_url: official ONNX embeds the character list in metadata (session.have_key() path), matching v4/v5 onnx convention
- verified: 4 v6 unit tests pass; det benchmark Hmean identical to prior mirror-based run (0.8263/0.8492/0.8421 for tiny/small/medium)
* chore: add pyproject toml configuration
* build: migrate RapidOCR wheel packaging to pyproject.toml
- add PEP 517 setuptools build configuration
- derive package version from git tags via setuptools-scm
- move wheel model preparation into an explicit tools script
- generate MANIFEST.in for default model assets before building
- avoid importing rapidocr during package metadata generation
* ci: build release wheels from validated git tags
* build: align package runtime support with Python 3.8
- set Requires-Python to >=3.8
- remove Python 3.6 and 3.7 classifiers
- make wheel asset preparation script type hints Python 3.8 compatible
- clarify split between build-time and wheel runtime support