fix(ml): pass model_root_dir to OcrOptions for RapidOCR compatibility (#28610)
* fix(ml): pass model_root_dir to OcrOptions for RapidOCR compatibility
Fix a TypeError (Path(None)) when the OCR model is invoked, caused by an upstream change in RapidOCR v3.8.1 (RapidAI/RapidOCR@8ea9626).
RapidOCR now internally calls `Path(cfg.get("model_root_dir"))`. Since `model_root_dir` was missing from `OcrOptions`, it evaluated to `None` and triggered a `TypeError: argument should be a str or an os.PathLike`.
This fix adds the missing `model_root_dir` argument to prevent the error.
Ref: #28331
* fix(ml-test): update OCR tests for RapidOCR schema change
* chore(ml-test): remove unused `cache_dir` parameter from `TextRecognizer`
* Revert "chore(ml-test): remove unused `cache_dir` parameter from `TextRecognizer`"
This reverts commit 007ad7b3f2.
* fix(ml): use self.cache_dir for model_root_dir in OcrOptions
pull/28685/head
parent
b189fc571c
commit
a838167f11
|
|
@ -64,6 +64,7 @@ class TextRecognizer(InferenceModel):
|
||||||
rec_batch_num=max_batch_size if max_batch_size else 6,
|
rec_batch_num=max_batch_size if max_batch_size else 6,
|
||||||
rec_img_shape=(3, 48, 320),
|
rec_img_shape=(3, 48, 320),
|
||||||
lang_type=self.language,
|
lang_type=self.language,
|
||||||
|
model_root_dir=self.cache_dir,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return session
|
return session
|
||||||
|
|
|
||||||
|
|
@ -1028,7 +1028,12 @@ class TestOcr:
|
||||||
text_recognizer.load()
|
text_recognizer.load()
|
||||||
|
|
||||||
rapid_recognizer.assert_called_once_with(
|
rapid_recognizer.assert_called_once_with(
|
||||||
OcrOptions(session=ort_session.return_value, rec_batch_num=6, rec_img_shape=(3, 48, 320))
|
OcrOptions(
|
||||||
|
session=ort_session.return_value,
|
||||||
|
rec_batch_num=6,
|
||||||
|
rec_img_shape=(3, 48, 320),
|
||||||
|
model_root_dir=text_recognizer.cache_dir,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_set_custom_max_batch_size(self, ort_session: mock.Mock, path: mock.Mock, mocker: MockerFixture) -> None:
|
def test_set_custom_max_batch_size(self, ort_session: mock.Mock, path: mock.Mock, mocker: MockerFixture) -> None:
|
||||||
|
|
@ -1041,7 +1046,12 @@ class TestOcr:
|
||||||
text_recognizer.load()
|
text_recognizer.load()
|
||||||
|
|
||||||
rapid_recognizer.assert_called_once_with(
|
rapid_recognizer.assert_called_once_with(
|
||||||
OcrOptions(session=ort_session.return_value, rec_batch_num=4, rec_img_shape=(3, 48, 320))
|
OcrOptions(
|
||||||
|
session=ort_session.return_value,
|
||||||
|
rec_batch_num=4,
|
||||||
|
rec_img_shape=(3, 48, 320),
|
||||||
|
model_root_dir=text_recognizer.cache_dir,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_ignore_other_custom_max_batch_size(
|
def test_ignore_other_custom_max_batch_size(
|
||||||
|
|
@ -1056,7 +1066,12 @@ class TestOcr:
|
||||||
text_recognizer.load()
|
text_recognizer.load()
|
||||||
|
|
||||||
rapid_recognizer.assert_called_once_with(
|
rapid_recognizer.assert_called_once_with(
|
||||||
OcrOptions(session=ort_session.return_value, rec_batch_num=6, rec_img_shape=(3, 48, 320))
|
OcrOptions(
|
||||||
|
session=ort_session.return_value,
|
||||||
|
rec_batch_num=6,
|
||||||
|
rec_img_shape=(3, 48, 320),
|
||||||
|
model_root_dir=text_recognizer.cache_dir,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue