Skip to content

Commit 4dcbd9b

Browse files
authored
fix: Exception handling for ONNX runtime on blank pages (#119)
This PR adds a try-catch during the inference with ONNX detectron2. A definitive solution would be to modify the ONNX model, however, doesn't seem like an easy change, and handling this error will allow the users to keep using the model.
1 parent eafbb28 commit 4dcbd9b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.1-dev0
2+
3+
* Hotfix to handle inference of blank pages using ONNX detectron2
4+
15
## 0.5.0
26

37
* Preserve image format in PIL.Image.Image when loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.5.0" # pragma: no cover
1+
__version__ = "0.5.1-dev0" # pragma: no cover

unstructured_inference/models/detectron2onnx.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def predict(self, image: Image.Image) -> List[LayoutElement]:
4949
super().predict(image)
5050

5151
prepared_input = self.preprocess(image)
52-
bboxes, labels, confidence_scores, _ = self.model.run(None, prepared_input)
52+
try:
53+
bboxes, labels, confidence_scores, _ = self.model.run(None, prepared_input)
54+
except onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException:
55+
logger.error("Something happened while inferencing page")
56+
return []
5357
input_w, input_h = image.size
5458
regions = self.postprocess(bboxes, labels, confidence_scores, input_w, input_h)
5559

0 commit comments

Comments
 (0)