Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commonforms/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def extract_widgets(
augment=True,
imgsz=image_size,
device=self.device,
agnostic_nms=True,
)

widgets = {}
Expand Down
19 changes: 18 additions & 1 deletion tests/inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from PIL import Image

from commonforms.inference import promote_signature_widgets
from commonforms.inference import FFDNetDetector, promote_signature_widgets
from commonforms.utils import BoundingBox, Page, TextFragment, Widget


Expand Down Expand Up @@ -71,6 +71,23 @@ def test_inference_ffdetr(tmp_path):
doc.document.close()


def test_ffdnet_enables_class_agnostic_nms():
class Model:
def predict(self, source, **kwargs):
assert len(source) == 1
assert kwargs["agnostic_nms"] is True
return []

detector = FFDNetDetector.__new__(FFDNetDetector)
detector.device = "cpu"
detector.fast = False
detector.model = Model()

pages = [Page(image=Image.new("RGB", (1, 1)), width=1, height=1, text_fragments=[])]

assert detector.extract_widgets(pages) == {}


def test_promote_signature_widgets_uses_signature_label_on_test_pdf():
pages = [
Page(
Expand Down