From bab9c25c0c876da0c06fe5a08fc72ad525c440b0 Mon Sep 17 00:00:00 2001 From: William Easton Date: Tue, 1 Jul 2025 10:43:30 -0500 Subject: [PATCH] Fix baseocrmodel test issue Signed-off-by: William Easton --- docling/models/base_ocr_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docling/models/base_ocr_model.py b/docling/models/base_ocr_model.py index dfad8fd2..67ada340 100644 --- a/docling/models/base_ocr_model.py +++ b/docling/models/base_ocr_model.py @@ -20,9 +20,6 @@ from docling.models.base_model import BaseModelWithOptions, BasePageModel _log = logging.getLogger(__name__) -if TYPE_CHECKING: - from scipy.ndimage import binary_dilation, find_objects, label - class BaseOcrModel(BasePageModel, BaseModelWithOptions): def __init__( @@ -33,6 +30,7 @@ class BaseOcrModel(BasePageModel, BaseModelWithOptions): options: OcrOptions, accelerator_options: AcceleratorOptions, ): + # Make sure any delay/error from import occurs on ocr model init and not first use from scipy.ndimage import binary_dilation, find_objects, label self.enabled = enabled @@ -40,6 +38,8 @@ class BaseOcrModel(BasePageModel, BaseModelWithOptions): # Computes the optimum amount and coordinates of rectangles to OCR on a given page def get_ocr_rects(self, page: Page) -> List[BoundingBox]: + from scipy.ndimage import binary_dilation, find_objects, label + BITMAP_COVERAGE_TRESHOLD = 0.75 assert page.size is not None