Skip to content

Commit b139d3b

Browse files
benjats07qued
andauthored
Fix for wrong type assignation at ingest-test (#172)
This PR restores some thresholds for getting the ingest test correct at `unstructured`, however, the thresholds keep being distinct for detectron2_mask_rcnn. --------- Co-authored-by: Alan Bertl <[email protected]>
1 parent 080ccfa commit b139d3b

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
sudo add-apt-repository -y ppa:alex-p/tesseract-ocr5
132132
sudo apt-get install -y tesseract-ocr
133133
sudo apt-get install -y tesseract-ocr-kor
134+
sudo apt-get install -y diffstat
134135
tesseract --version
135136
make install-ingest-s3
136137
make install-ingest-azure

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.18
2+
3+
* Fix for incorrect type assignation at ingest test
4+
15
## 0.5.17
26

37
* Use `OMP_THREAD_LIMIT` to improve tesseract performance
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.5.17" # pragma: no cover
1+
__version__ = "0.5.18" # pragma: no cover

unstructured_inference/inference/layout.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
from unstructured_inference.inference.ordering import order_layout
2929
from unstructured_inference.logger import logger
3030
from unstructured_inference.models.base import get_model
31+
from unstructured_inference.models.detectron2onnx import (
32+
UnstructuredDetectronONNXModel,
33+
)
3134
from unstructured_inference.models.unstructuredmodel import (
3235
UnstructuredElementExtractionModel,
3336
UnstructuredObjectDetectionModel,
@@ -262,15 +265,33 @@ def get_elements_with_detection_model(
262265
raise ValueError("Invalid OCR mode")
263266

264267
if self.layout is not None:
268+
threshold_kwargs = {}
269+
# NOTE(Benjamin): With this the thresholds are only changed for detextron2_mask_rcnn
270+
# In other case the default values for the functions are used
271+
if (
272+
isinstance(self.detection_model, UnstructuredDetectronONNXModel)
273+
and "R_50" not in self.detection_model.model_path
274+
):
275+
threshold_kwargs = {"same_region_threshold": 0.5, "subregion_threshold": 0.5}
265276
inferred_layout = merge_inferred_layout_with_extracted_layout(
266277
inferred_layout=inferred_layout,
267278
extracted_layout=self.layout,
268279
ocr_layout=ocr_layout,
280+
**threshold_kwargs,
269281
)
270282
elif ocr_layout is not None:
283+
threshold_kwargs = {}
284+
# NOTE(Benjamin): With this the thresholds are only changed for detextron2_mask_rcnn
285+
# In other case the default values for the functions are used
286+
if (
287+
isinstance(self.detection_model, UnstructuredDetectronONNXModel)
288+
and "R_50" not in self.detection_model.model_path
289+
):
290+
threshold_kwargs = {"subregion_threshold": 0.3}
271291
inferred_layout = merge_inferred_layout_with_ocr_layout(
272292
inferred_layout=inferred_layout,
273293
ocr_layout=ocr_layout,
294+
**threshold_kwargs,
274295
)
275296

276297
elements = self.get_elements_from_layout(cast(List[TextRegion], inferred_layout))

0 commit comments

Comments
 (0)