diff --git a/src/eynollah/ocrd-tool.json b/src/eynollah/ocrd-tool.json index 5e36ecb..8d9b901 100644 --- a/src/eynollah/ocrd-tool.json +++ b/src/eynollah/ocrd-tool.json @@ -6,23 +6,61 @@ "ocrd-eynollah-segment": { "executable": "ocrd-eynollah-segment", "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, "output_file_grp_cardinality": 1, "steps": ["layout/segmentation/region", "layout/segmentation/line"], "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": { "type": "string", "format": "uri", "content-type": "text/directory", "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 }, + "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": { "type": "number", "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 }, "full_layout": { @@ -57,10 +95,20 @@ "default": false, "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": { "type": "boolean", "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": { "type": "boolean", @@ -72,6 +120,20 @@ "default": false, "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": { "type": "boolean", "default": false, @@ -159,6 +221,14 @@ } }, "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", "name": "models_inference_all_v0_9_1", diff --git a/src/eynollah/processor.py b/src/eynollah/processor.py index 684b0d5..bc62ead 100644 --- a/src/eynollah/processor.py +++ b/src/eynollah/processor.py @@ -15,7 +15,12 @@ class EynollahProcessor(Processor): def setup(self) -> None: assert self.parameter 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( model_zoo=model_zoo, allow_enhancement=self.parameter['allow_enhancement'], @@ -23,10 +28,15 @@ class EynollahProcessor(Processor): right2left=self.parameter['right_to_left'], reading_order_machine_based=self.parameter['reading_order_machine_based'], 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'], allow_scaling=self.parameter['allow_scaling'], headers_off=self.parameter['headers_off'], 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 ) self.eynollah.plotter = None @@ -49,13 +59,17 @@ class EynollahProcessor(Processor): \b - If ``tables``, try to detect table blocks and add them as TableRegion. - - If ``full_layout``, then in addition to paragraphs and marginals, also - try to detect drop capitals and headings. + - If ``full_layout`` (the default), then in addition to paragraphs and marginals, + 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 ``curved_line``, then compute contour polygons for text lines instead of simple bounding boxes. - If ``reading_order_machine_based``, then detect reading order via 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. """