Merge in RR/image-prediction from image_representation_metadata to master
Squashed commit of the following:
commit bfe92b24a2959a72c0e913ef051476c01c285ad0
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Thu May 12 11:24:12 2022 +0200
updated comment
commit f5721560f3fda05a8ad45d0b5e406434204c1177
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Thu May 12 11:16:02 2022 +0200
unskip server predict test
commit 41d94199ede7d58427b9e9541605a94f962c3dc4
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Thu May 12 11:15:48 2022 +0200
added hash image encoder that produces representations by hashing
commit 84a8b0a290081616240c3876f8db8a1ae8592096
Merge: 1624ee4 6030f40
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Thu May 12 10:18:56 2022 +0200
Merge branch 'master' of ssh://git.iqser.com:2222/rr/image-prediction
commit 1624ee40376b84a4519025343f913120c464407a
Author: Matthias Bisping <Matthias.Bisping@iqser.com>
Date: Mon Apr 25 16:51:13 2022 +0200
Pull request #11: fixed assignment
Merge in RR/image-prediction from image_prediction_service_overhaul_xref_and_empty_result_fix_fix to master
Squashed commit of the following:
commit 7312e57d1127b081bfdc6e96311e8348d3f8110d
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Apr 25 16:45:12 2022 +0200
logging setup changed
commit 955e353d74f414ee2d57b234bdf84d32817d14bf
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Apr 25 16:37:52 2022 +0200
fixed assignment
76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
import math
|
|
from operator import itemgetter
|
|
|
|
from image_prediction.config import CONFIG
|
|
from image_prediction.transformer.transformer import Transformer
|
|
from image_prediction.utils import get_logger
|
|
|
|
logger = get_logger()
|
|
|
|
|
|
class ResponseTransformer(Transformer):
|
|
def transform(self, data):
|
|
logger.debug("ResponseTransformer.transform")
|
|
return build_image_info(data)
|
|
|
|
|
|
def build_image_info(data: dict) -> dict:
|
|
def compute_geometric_quotient():
|
|
page_area_sqrt = math.sqrt(abs(page_width * page_height))
|
|
image_area_sqrt = math.sqrt(abs(x2 - x1) * abs(y2 - y1))
|
|
return image_area_sqrt / page_area_sqrt
|
|
|
|
page_width, page_height, x1, x2, y1, y2, width, height, alpha = itemgetter(
|
|
"page_width", "page_height", "x1", "x2", "y1", "y2", "width", "height", "alpha"
|
|
)(data)
|
|
|
|
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)
|
|
min_image_width_to_height_quotient_breached = bool(
|
|
width / height < CONFIG.filters.image_width_to_height_quotient.min
|
|
)
|
|
max_image_width_to_height_quotient_breached = bool(
|
|
width / height > CONFIG.filters.image_width_to_height_quotient.max
|
|
)
|
|
|
|
classification = data["classification"]
|
|
representation = data["representation"]
|
|
|
|
min_confidence_breached = bool(max(classification["probabilities"].values()) < CONFIG.filters.min_confidence)
|
|
|
|
image_info = {
|
|
"classification": classification,
|
|
"representation": representation,
|
|
"position": {"x1": x1, "x2": x2, "y1": y1, "y2": y2, "pageNumber": data["page_idx"] + 1},
|
|
"geometry": {"width": width, "height": height},
|
|
"alpha": alpha,
|
|
"filters": {
|
|
"geometry": {
|
|
"imageSize": {
|
|
"quotient": quotient,
|
|
"tooLarge": max_image_to_page_quotient_breached,
|
|
"tooSmall": min_image_to_page_quotient_breached,
|
|
},
|
|
"imageFormat": {
|
|
"quotient": round(width / height, 4),
|
|
"tooTall": min_image_width_to_height_quotient_breached,
|
|
"tooWide": max_image_width_to_height_quotient_breached,
|
|
},
|
|
},
|
|
"probability": {"unconfident": min_confidence_breached},
|
|
"allPassed": not any(
|
|
[
|
|
max_image_to_page_quotient_breached,
|
|
min_image_to_page_quotient_breached,
|
|
min_image_width_to_height_quotient_breached,
|
|
max_image_width_to_height_quotient_breached,
|
|
min_confidence_breached,
|
|
]
|
|
),
|
|
},
|
|
}
|
|
|
|
return image_info
|