processor: pass on more Eynollah parameters…

- `device` selection
- `model_overrides` (as dict; including relative path resolution), e.g.
```JSON
{
  "binarization": {
    "":
      "models_inference_layout_v0_9_1/models_eynollah/eynollah-binarization_20210425.onnx"
  }
}
```
- `skip_layout_and_reading_order`
- `num_col_upper`
- `num_col_lower`
- `binarize` (for `input_binary`, which is a misnomer)
This commit is contained in:
Robert Sachunsky 2026-07-17 15:37:39 +02:00
parent f579d12866
commit c1b276fea1
2 changed files with 91 additions and 7 deletions

View file

@ -6,23 +6,61 @@
"ocrd-eynollah-segment": { "ocrd-eynollah-segment": {
"executable": "ocrd-eynollah-segment", "executable": "ocrd-eynollah-segment",
"categories": ["Layout analysis"], "categories": ["Layout analysis"],
"description": "Segment page into regions and lines and do reading order detection with eynollah", "description": "Segment page into regions and lines and detect reading order with Eynollah",
"input_file_grp_cardinality": 1, "input_file_grp_cardinality": 1,
"output_file_grp_cardinality": 1, "output_file_grp_cardinality": 1,
"steps": ["layout/segmentation/region", "layout/segmentation/line"], "steps": ["layout/segmentation/region", "layout/segmentation/line"],
"parameters": { "parameters": {
"device": {
"type": "string",
"default": "",
"description": "Allocate models to computation device; can be a single device name for all models, or a comma-delimited, colon-tagged mapping from model category to device name (where model categories are binarization, col_classifier, page, textline, region_1_2, region_fl_np, table, reading_order, but can be abbreviated by glob expressions), e.g. col*:CPU,page:GPU0,*:GPU1. If empty, selects the first available GPU for all models."
},
"models": { "models": {
"type": "string", "type": "string",
"format": "uri", "format": "uri",
"content-type": "text/directory", "content-type": "text/directory",
"cacheable": true, "cacheable": true,
"description": "Directory containing models to be used (See https://qurator-data.de/eynollah)", "description": "Directory containing models to be used (See https://huggingface.co/collections/SBB/eynollah-models)",
"required": true "required": true
}, },
"model_overrides": {
"type": "object",
"properties": {
"binarization": {
"type": "object"
},
"enhancement": {
"type": "object"
},
"col_classifier": {
"type": "object"
},
"page": {
"type": "object"
},
"textline": {
"type": "object"
},
"region_1_2": {
"type": "object"
},
"region_fl_np": {
"type": "object"
},
"table": {
"type": "object"
},
"reading_order": {
"type": "object"
}
},
"description": "Map model categories to mappings from model variant to model path, e.g. {'ocr': {'tr': 'path/to/my/trocr-model'}}."
},
"dpi": { "dpi": {
"type": "number", "type": "number",
"format": "float", "format": "float",
"description": "pixel density in dots per inch (overrides any meta-data in the images); ignored if <= 0 (with fall-back 230)", "description": "ignored (only for backwards-compatibility)",
"default": 0 "default": 0
}, },
"full_layout": { "full_layout": {
@ -57,10 +95,20 @@
"default": false, "default": false,
"description": "if true, do not attempt page frame detection (cropping)" "description": "if true, do not attempt page frame detection (cropping)"
}, },
"skip_layout_and_reading_order": {
"type": "boolean",
"default": false,
"description": "skip regions, only run textlines, stuffing them in a single text region for the entire page"
},
"binarize": {
"type": "boolean",
"default": false,
"description": "run adaptive thresholding on input image with dedicated model before analysis (may be useful for degraded input)."
},
"allow_scaling": { "allow_scaling": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description": "check the resolution against the number of detected columns and if needed, scale the image up or down during layout detection (heuristic to improve quality and performance)" "description": "ignored (only for backwards-compatibility)"
}, },
"allow_enhancement": { "allow_enhancement": {
"type": "boolean", "type": "boolean",
@ -72,6 +120,20 @@
"default": false, "default": false,
"description": "if true, return reading order in right-to-left reading direction." "description": "if true, return reading order in right-to-left reading direction."
}, },
"num_col_upper": {
"type": "number",
"format": "integer",
"minimum": 0,
"default": 0,
"description": "Constrain detection of number of columns by this upper boundary (ignored when zero)."
},
"num_col_lower": {
"type": "number",
"format": "integer",
"minimum": 0,
"default": 0,
"description": "Constrain detection of number of columns by this lower boundary (ignored when zero)."
},
"headers_off": { "headers_off": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
@ -159,6 +221,14 @@
} }
}, },
"resources": [ "resources": [
{
"url": "https://zenodo.org/records/21381102/files/models_inference_layout_v0_9_1.zip",
"name": "models_inference_layout_v0_9_1",
"type": "archive",
"size": 1847700967,
"description": "Models for layout detection, reading order detection, textline detection, page extraction, column classification, table detection, binarization and image enhancement",
"version_range": ">= v0.9.0"
},
{ {
"url": "https://zenodo.org/records/21381102/files/models_inference_all_v0_9_1.zip", "url": "https://zenodo.org/records/21381102/files/models_inference_all_v0_9_1.zip",
"name": "models_inference_all_v0_9_1", "name": "models_inference_all_v0_9_1",

View file

@ -15,7 +15,12 @@ class EynollahProcessor(Processor):
def setup(self) -> None: def setup(self) -> None:
assert self.parameter assert self.parameter
basedir = self.resolve_resource(self.parameter['models']) basedir = self.resolve_resource(self.parameter['models'])
model_zoo = EynollahModelZoo(basedir) overrides = []
for category, override in self.parameter['model_overrides'].items():
for variant, path in override.items():
path = self.resolve_resource(path)
overrides.append((category, variant, path))
model_zoo = EynollahModelZoo(basedir, model_overrides=overrides)
self.eynollah = Eynollah( self.eynollah = Eynollah(
model_zoo=model_zoo, model_zoo=model_zoo,
allow_enhancement=self.parameter['allow_enhancement'], allow_enhancement=self.parameter['allow_enhancement'],
@ -23,10 +28,15 @@ class EynollahProcessor(Processor):
right2left=self.parameter['right_to_left'], right2left=self.parameter['right_to_left'],
reading_order_machine_based=self.parameter['reading_order_machine_based'], reading_order_machine_based=self.parameter['reading_order_machine_based'],
ignore_page_extraction=self.parameter['ignore_page_extraction'], ignore_page_extraction=self.parameter['ignore_page_extraction'],
skip_layout_and_reading_order=self.parameter['skip_layout_and_reading_order'],
full_layout=self.parameter['full_layout'], full_layout=self.parameter['full_layout'],
allow_scaling=self.parameter['allow_scaling'], allow_scaling=self.parameter['allow_scaling'],
headers_off=self.parameter['headers_off'], headers_off=self.parameter['headers_off'],
tables=self.parameter['tables'], tables=self.parameter['tables'],
device=self.parameter['device'],
input_binary=self.parameter['binarize'],
num_col_upper=self.parameter['num_col_upper'],
num_col_lower=self.parameter['num_col_lower'],
logger=self.logger logger=self.logger
) )
self.eynollah.plotter = None self.eynollah.plotter = None
@ -49,13 +59,17 @@ class EynollahProcessor(Processor):
\b \b
- If ``tables``, try to detect table blocks and add them as TableRegion. - If ``tables``, try to detect table blocks and add them as TableRegion.
- If ``full_layout``, then in addition to paragraphs and marginals, also - If ``full_layout`` (the default), then in addition to paragraphs and marginals,
try to detect drop capitals and headings. also try to detect drop capitals and headings.
- If ``ignore_page_extraction``, then attempt no cropping of the page.
- If ``ignore_page_extraction``, then attempt no cropping of the page. - If ``ignore_page_extraction``, then attempt no cropping of the page.
- If ``curved_line``, then compute contour polygons for text lines - If ``curved_line``, then compute contour polygons for text lines
instead of simple bounding boxes. instead of simple bounding boxes.
- If ``reading_order_machine_based``, then detect reading order via - If ``reading_order_machine_based``, then detect reading order via
data-driven model instead of geometrical heuristics. data-driven model instead of geometrical heuristics.
- If ``binarize``, then run internal binarization on the raw image.
- If ``num_col_upper`` or ``num_col_lower`` are non-zero, these will
constrain the column detection (upper or lower bound, respectively).
Produce a new output file by serialising the resulting hierarchy. Produce a new output file by serialising the resulting hierarchy.
""" """