RED-5202 add per class customizable max image to page quotient setting for signatures, default is 0.4. Can be overwritten by , set to null to use default value or set to value that should be used.

This commit is contained in:
Julius Unverfehrt 2022-09-12 08:47:02 +02:00
parent ebfdc14265
commit 5f99622646
5 changed files with 52 additions and 2 deletions

View File

@ -18,6 +18,9 @@ filters:
image_to_page_quotient: # Image size to page size ratio (ratio of geometric means of areas)
min: $MIN_REL_IMAGE_SIZE|0.05 # Minimum permissible
max: $MAX_REL_IMAGE_SIZE|0.75 # Maximum permissible
customized: # Customized settings per class (RED-5202)
max:
signature: $MAX_REL_SIGNATURE_SIZE|0.4
image_width_to_height_quotient: # Image width to height ratio
min: $MIN_IMAGE_FORMAT|0.1 # Minimum permissible

View File

@ -15,6 +15,12 @@ class DotIndexable:
def __init__(self, x):
self.x = x
def get(self, item, default=None):
try:
return _get_item_and_maybe_make_dotindexable(self.x, item)
except (KeyError, TypeError):
return default
def __getattr__(self, item):
return _get_item_and_maybe_make_dotindexable(self.x, item)

View File

@ -27,7 +27,9 @@ def build_image_info(data: dict) -> dict:
quotient = round(compute_geometric_quotient(), 4)
min_image_to_page_quotient_breached = bool(quotient < CONFIG.filters.image_to_page_quotient.min)
max_image_to_page_quotient_breached = bool(quotient > CONFIG.filters.image_to_page_quotient.max)
max_image_to_page_quotient_breached = is_max_image_to_page_quotient_breached(
quotient, data["classification"]["label"]
)
min_image_width_to_height_quotient_breached = bool(
width / height < CONFIG.filters.image_width_to_height_quotient.min
)
@ -73,3 +75,11 @@ def build_image_info(data: dict) -> dict:
}
return image_info
def is_max_image_to_page_quotient_breached(quotient, label):
default_max_quotient = CONFIG.filters.image_to_page_quotient.max
customized_entries = CONFIG.filters.image_to_page_quotient.customized.max
max_quotient = customized_entries.get(label, default_max_quotient)
max_quotient = max_quotient if max_quotient else default_max_quotient
return bool(quotient > max_quotient)

View File

@ -3,7 +3,7 @@ import tempfile
import pytest
import yaml
from image_prediction.config import Config
from image_prediction.config import Config, DotIndexable
@pytest.fixture
@ -36,3 +36,13 @@ def test_dot_access_key_does_not_exists(config):
def test_access_key_does_not_exists(config):
assert config["B"] is None
def test_get_method_returns_key_if_key_does_exist(config):
dot_indexable = config.D.E
assert dot_indexable.get("F", "default_value") == True
def test_get_method_returns_default_if_key_does_not_exist(config):
dot_indexable = config.D.E
assert dot_indexable.get("X", "default_value") == "default_value"

View File

@ -0,0 +1,21 @@
import pytest
from image_prediction.transformer.transformers.response import is_max_image_to_page_quotient_breached
@pytest.fixture
def expected_is_breached(quotient, label):
if label == "signature" and quotient < 0.4:
return False
elif label == "signature" and quotient >= 0.4:
return True
elif quotient < 0.7:
return False
else:
return True
@pytest.mark.parametrize("quotient", [0.1, 0.5])
@pytest.mark.parametrize("label", ["logo", "signature"])
def test_customized_per_label_ratio_breach(quotient, label, expected_is_breached):
assert is_max_image_to_page_quotient_breached(quotient, label) == expected_is_breached