eynollah

qurator-spkApache-2.0活跃维护

面向 OCR 流程的文档版面分析工具,能自动切分页面区域、检测文本行并做二值化,为后续文字识别和 RAG 检索提供干净的结构化输入。

Document Layout Analysis

v0.10.0发布于 2026-11-06 17:34 UTC418star +1 / 7 天37fork同步于 2026-11-10 23:58 UTC

怎么上手

由 README 提炼,执行前请确认
pip install eynollah
硬件要求按 README 说明

README 说明目前支持 Linux 上的 ONNX Runtime;GPU 需安装支持 CUDA 12 的 Nvidia 驱动,ONNX、TensorRT 与 CUDA 运行库(含 cuDNN)由 PyPI 依赖拉取。README 未给出显存要求,也未说明是否支持非 Nvidia GPU。

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

面向历史文档的版面分析工具,用深度学习加启发式规则做分割、二值化与 OCR

面向 OCR 流程的文档版面分析工具,能自动切分页面区域、检测文本行并做二值化,为后续文字识别和 RAG 检索提供干净的结构化输入。

核心能力

  • 支持背景、页边、文本区、文本行、标题、图片、表格等 10 类分割
  • 文本行可输出边界框或多边形,支持弯曲行与竖排文字
  • 内置二值化、图像增强与 CNN-RNN/TrOCR 文本识别
  • 检测从左到右或从右到左的阅读顺序
  • 输出 PAGE-XML,并提供 OCR-D 接口

容易踩的坑

需从 Zenodo 单独下载预训练模型,推理用 models_inference_...zip 变体;OCR 功能需额外执行 pip install "eynollah[OCR]",且依赖 Tensorflow(含 tf-keras)或 Torch(含 transformers),CUDA 依赖可能冲突;处理速度较慢,因组合多个深度学习模型与启发式规则。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.10.0
  1. v0.10.0最新正式版2026-11-06 · 2026-11-06 17:34 UTC

    🎯 for accuracy improvements 💪 for stability and robustness 🏃 for efficiency :fire: for user attention advised

    Fixed:

    • 💪 avoid zero division during confidence calculations
    • 🎯 textline ordering (horizontal vs. vertical)
    • 🎯 edge case: excentric textlines
    • 🎯 region angle estimation: numeric range
    • 🎯 prediction tiling: avoid self-overlapping windows
    • 🎯 early layout segment boundaries: ensure instances are still separated after dilation
    • 🎯 cropping: apply upper page bounds to seplines, too
    • 💪 edge cases in RO column detector
    • 💪 stability in polygon handling

    Added:

    • CLI subcommand eynollah extract-page for cropping (w/ optional deskewing)
    • CLI flag eynollah --version to get the currently installed version
    • test coverage for tiling

    Removed:

    • :fire: Python 3.8 support

    Changed:

    • refactored further:
      • move do_prediction* to utils.tiling
      • retrieve external contours directly (instead of filtering from contour tree)
      • avoid unnecessary calculations
      • remove unused functions
      • reduce code duplication
      • make code more readable
      • update type hinting
      • make work with linter
    • made page deskewing faster, more robust and precise:
      • 🏃 avoid unnecessary floating-point precision for rotations
      • 🏃 also downsize 3-6 column pages (for speed)
      • introduce a confidence measure
      • 🎯💪 stay on 0° if minimum confidence unmet
      • 🎯 for multi-column pages, use column signal if better than row signal (as either can be occluded in the layout)
      • 🎯🏃 use local maximum optimization instead of slow/imprecise grid search
    • region angle estimation:
      • 🎯💪 improved accuracy and robustness
    • layout model for early regions:
      • 🎯 increase tile size for 3-6 column pages (i.e. fewer tiles w/ less myopia :mag:)
    • layout model decoding:
      • 🎯🏃 deskew text contours directly instead of finding deskewed contours and matching them to original contours
      • 🎯 ignore separators from full layout model
      • 🎯 ignore too small drop-capitals from full model consistently
      • :fire: open holes (i.e. cut into interiors) of separator polygons, allowing for flat segmentation of frames etc.
      • increase minimum area for text, table and drop-capital regions
      • reduce minimum area for textlines
    • rewrote marginalia detection to make faster and more accurate:
      • avoid resizing arrays
      • forbid points spanned by separators or images
      • 1st stage (gap detection): constrain gap prominence, too
      • 2nd stage (step detection, i.e. jump+plateau) for marginals close to main
      • contour stage (main/marg assignment): precise polygon (re)construction, also splitting partial overlaps
      • final stage (textline mask) for splitting textlines
      • :fire: add CLI option --allow_marginalia both|left|right|off (with both still default for 1-2 column pages)
      • optionally (--paragraphs_from_marginalia): also cut adjacent main regions between closest textline pair (creating paragraphs preceding/following marginalia)
    • improve reading order:
      • avoid eroding off small regions
      • also split pages at horizontal gaps (allowing distinctly columned parts)
      • dont' split pages around image regions (cutting them in half)
      • don't suppress crossings of horizontal w/ vertical separators
      • column detection: fix dtype to prevent underflow
      • improve rules for cutting through cross-column regions
      • replace within-column ordering by simpler, faster, more robust algorithm (which also enforces the right2left setting)
      • :fire: order marginalia along with main paragraphs (instead of left→main→right)
      • :fire: represent left vs right marginalia by @custom="layout {sub_type:margi_left;}" (or margi_right)
      • :fire: order tables and images along with text regions, too
    • :fire: Subcommand eynollah machine-based-reading-order renamed as eynollah reorder
    • :fire: Trai
  2. v0.9.22026-07-28 · 2026-07-28 13:42 UTC
    查看更新说明

    Fixed:

    • return_deskew_slop: typo caused silent exit for landscape pages, #223, #224, ht @lazyants @SAY-5

    Merged PR:

  3. v0.9.12026-07-20 · 2026-07-20 18:09 UTC
    查看更新说明

    Fixed:

    • Base image version must be >= core 3.13.2 for ONNX base image, OCR-D/core#1365
  4. v0.9.02026-07-20 · 2026-07-20 17:17 UTC
    查看更新说明

    Fixed:

    • CLIs for reorder and OCR: make work again
    • more robust predictor/model shutdown
    • :fire: do_order_of_regions: rm overcautious assertion
    • :fire: correctly order textlines again
    • make utils.contours.make_valid() even more robust
    • :fire: region-wise deskewing w/o -cl: typo when only single usable textline
    • Keras OCR (cnn-rnn-ocr):
      • training.models: correct config names for height and width
      • utils_ocr: rare errors
      • run_single() w/o overwrite: skip instead of return
    • OCR-D layout processor:
      • :fire: resolve filesystem paths for models resource names again
      • :fire: avoid writing secondary .xml into workspace

    Changed:

    • CLIs: remove redundant negative options, add -h everywhere, show defaults
    • move --device option to group level, apply to all model types (including Torch/ONNX)
    • load models w/ memory_limit instead of memory_growth strategy (faster and less VRAM)
    • show full stacktrace in case predictor fails (not just exception name)
    • :fire: default to ONNX inference w/ TensorRT instead of TF (much faster, but requires warmup phase w/ persistent cache directory $XDG_CONFIG_HOME)
    • :fire: published new set of models, both for training (TF/Keras) and inference (ONNX) – rebuilt from code changes (see below), not retrained
    • :fire: Docker image now based on ocrd/core-cuda-onnx for layout only, no [OCR] in Docker ATM
    • OCR: run pages in parallel (as for layout) via forking, add --halt-fail and --num-jobs, too
    • improve layout:
      • for heuristic reading order, do not try to elongate horizontal separators
      • when column classifier is confident enough, do maximally enlarge the image (for 6 columns or more)
    • improve TrOCR:
      • refactor, simplify
      • batch over entire page (faster)
      • extract confidence, too
      • use beam search instead of greedy decoder
      • load model and preprocessor/tokenizer into one object (no need for distinct models)
      • no need to resize images in advance
      • if set, apply -nmtc here, too
      • skip lines lower than -min_conf instead of setting empty string
    • improve Keras OCR:
      • refactor, simplify
      • batch over entire page (faster)
      • use correct confidence estimation
      • run binarization ad-hoc (if not provided)
      • adapt to all-in-one inference model
      • get image size from model (instead of fixed)
      • apply -min_conf here, too
      • skip lines lower than -min_conf instead of setting empty string
      • separate off .png files if dir_in_bin==dir_in
      • batch flipped line candidates together with normal lines
    • training/setup:
      • refactor imports from .models (single auto-configured get_model() call, no custom_objects loading)
      • drop new setting reload_weights in favour of --rebuild option for new CLI eynollah-training convert
      • new CLI for model conversion between Keras (formats HDF5 / native Keras, TF SavedModel), TF-Serving (i.e. model.export()) and ONNX
      • extract MusicRegion from PAGE GT, too
    • training/models:
      • ViT models: use Keras Reshape layer instead of ad-hoc tf.reshape
      • ViT models: use tf.map_fn to iterate over batch in tf.image.extract_patches for attention (faster, less VRAM, makes ONNX conversion work)
      • Keras (CNN-RNN) OCR backend: replace Conv1D(channels_first) (not fully supported by TF/CUDNN on CPU) by Conv1D(channels_last) w/ Permute layers
      • Keras (CNN-RNN) OCR training→inference conversion: encapsulate CTC decoder and inverse string lookup by model itself (no need for extra models and files, all on GPU), always ensemble RGB and binarized input

    Added:

    • inference backends for TF-Serving and ONNX/TensorRT, differentiate by loaded model type
    • integrate training for TrOCR (still untested!)
    • integrate weight ensembling for TrOCR
    • integrate standalone inference for TrOCR
    • OCR-D processor: pass on more paramete
  5. v0.8.02026-05-11 · 2026-05-11 11:18 UTC
    查看更新说明
    • Optimize model performance
      • multiprocessing.SpawnProcess predictor wrapper for models to have commmunication with Tensorflow in a separate subprocess in a task queue with parallel jobs configurable via --num-jobs and maximum number of failed jobs via --halt-fail
      • Keep batch size low enough for processing fitting into common 8GB GPU (with model-dependent batch resizing prepared but not yet active)
      • GPU device can be selected manually with --device
      • Handle image resizing and tiling in GPU as much as possible to avoid overhead of switching between GPU and CPU
      • jit-compile and precompile models where possible (non-autosized, non-patched Keras models)
      • Fix bugs and homogenize internal labels related to differing labels for early layout and different stages of full layout detection
      • Replace Lambda layers with ZeroPadding2D, improving size and optimizability of models for eynollah layout
    • Improved training
      • Use connected components for loss function
      • Integrate with Tensorboard to observe model training progress, including plots and visualizing intermediate evaluation results
    • Simplified model usage
      • Models can be overridden individually, so any model trained with eynollah-training can replace any model in the distributions on zenodo
      • --model is a CLI option of the eynollah root CLI now and should point to the same directory for all subcommands
    • Improved reading order detection heuristics
    • Improved drop capital, marginalia and column detection
    • Fixing bugs in polygon handling and image operations
      • No more self-intersecting polygons
      • Correct rotation implementation, enlarging/shrinking canvas as necessary
      • Use actual area of a polygon instead of length of polygon path or first candidate for comparisons
    • Improved PAGE-XML serialization
      • Annotate column classifier result in /PcGts/Page/@custom (Transkribus convention) and /PcGts/Metadata/Comment (QURATOR convention)
      • Annotate page skew in /PcGts/Page/@orientation
      • Calculate and annotate confidences as Coords/@conf for regions, lines, images and tables
    • Massive refactoring and code quality improvement
      • deduplication, idiomatic python, clean parallel processing, class reuse, consistent and meaningful naming

    NOTE We are aware of a possible issue with regards to the cropping of images. It appears that we have not consistenly cropped images in training. This can lead to suboptimal results for cropped images. If you experience quality issues with the eynollah layout, try setting the -ipe/--ignore_page_extraction option to skip the builtin cropping. We will rectify this in the next trainings.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Eynollah

    Document Layout Analysis, Binarization and OCR with Deep Learning Models and Heuristics

    Python Versions PyPI Version GH Actions Test GH Actions Deploy License: ASL DOI

    Features

    :warning: Development is focused on achieving the optimal quality for a wide variety of historical documents using a combination of multiple deep learning models and heuristics; therefore processing can be slow.

    Installation

    Python 3.9-3.11 with ONNX Runtime on Linux are currently supported.

    For GPU support, Nvidia drivers supporting CUDA 12 must be installed. The runtime dependencies will pull in ONNX, TensorRT and CUDA runtime libraries (including cuDNN) from PyPI.

    You can either install from PyPI

    pip install eynollah
    

    or clone the repository, enter it and install (editable) with

    git clone [email protected]:qurator-spk/eynollah.git
    cd eynollah; pip install -e .
    

    To also install the dependencies for the OCR engines:

    pip install "eynollah[OCR]"
    

    :warning: Requirements for OCR are more involved, as they need Tensorflow (with tf-keras) and/or Torch (with transformers), which may also have conflicting CUDA dependencies. An ONNX conversion for these models may be achieved soon.

    Models

    Pretrained models can be downloaded from Zenodo. For model documentation and model cards, see models.md.

    Two model variants are provided:

    • For faster runtime inference, download the ONNX model variants distributed as models_inference_...zip
    • For finetuning and training, download the original (Tensorflow / Torch) models distributed as models_training...zip

    To train your own model with Eynollah, see train.md.

    Usage

    Eynollah supports five use cases:

    1. layout analysis (segmentation),
    2. binarization,
    3. image enhancement,
    4. text recognition (OCR), and
    5. reading order detection.

    The generic options shared by all subcommands are:

      -m <directory containing model files>
      -mv <model category> <model variant> <model path>
      -D <device specifier>
      -l <log level>
    

    Layout Analysis

    Detect layout elements and their reading order.

    The command-line interface for layout analysis can be called like this:

    eynollah [GENERIC_OPTIONS] layout \
      -i <single image file> | -di <directory containing image files> \
      -o <output directory> \
         [OPTIONS]
    

    The following options can be used to further configure the processing:

    optiondescription
    -flapply full layout analysis including all steps and classes (recommended)
    -tabapply table detection
    -aeapply image enhancement (the resulting image is saved to the output directory)
    -asapply automatic scaling
    -clapply contour detection for curved text lines, deskewing all regions independently
    -ibapply binarization (the resulting bitonal image is saved to the output directory)
    -epenable plotting (MUST always be used with -sl, -sd, -sa, -si or -ae)
    -hoignore headers for reading order detection
    -si <directory>save detected image regions to this directory
    -sd <directory>save deskewed image to this directory
    -sl <directory>save layout prediction as plot to this directory
    -sp <directory>save cropped page image to this directory
    -sa <directory>save all (plot, enhanced/binary image, layout) to this directory
    -thartconfidence threshold of artificial boundary class during textline detection
    -tharlconfidence threshold of artificial boundary class during region detection
    -ncuset upper limit of columns in document image
    -nclset lower limit of columns in document image
    -slroskip layout detection and reading order
    -rombapply machine learning based reading order detection
    -ipeignore page extraction
    -jnumber of CPU jobs to run parallel (useful with -di)
    -Hwhen to halt when some jobs fail

    Binarization

    Perform document image binarization.

    The command-line interface for binarization can be called like this:

    eynollah [GENERIC_OPTIONS] binarization \
      -i <single image file> | -di <directory containing image files> \
      -o <output directory> \
      [OPTIONS]
    

    Image Enhancement

    Enlarge and enhance images. Useful when the scan quality is low.

    The command-line interface for image enhancement can be called like this:

    eynollah [GENERIC_OPTIONS] enhancement \
      -i <single image file> | -di <directory containing image files> \
      -o <output directory> \
      [OPTIONS]
    

    The following options can be used to further configure the processing:

    optiondescription
    -sossave the enhanced image in original image size
    -ncuupper limit of columns in document image
    -ncllower limit of columns in document image

    OCR

    Perform text recognition using either a CNN-RNN model (default) or a TrOCR model. Needs a PAGE-XML input file containing textline segmentation information.

    The command-line interface for OCR can be called like this:

    eynollah [GENERIC_OPTIONS] ocr \
      -i <single image file> | -di <directory containing image files> \
      -xml <page-xml input file> | -dx <directory containing page-xml files> \
      -o <output directory> \
    

    The following options can be used to further configure the processing:

    optiondescription
    -trocruse TrOCR model instead of CNN-RNN model
    -dibdirectory of binarized images (file type must be '.png'), prediction with both RGB and bin
    -doitdirectory for output images rendered with the predicted text
    -nmtccropped textline images will not be masked with textline contour
    -bsOCR inference batch size. Default batch size is 2 for TrOCR and 8 for CNN-RNN models
    -min_confminimum OCR confidence value. OCR with textline confidence lower than this will be ignored

    Reading Order Detection

    Detect reading order using a machine learning based model. Needs a PAGE-XML input file containing textline segmentation information.

    The command-line interface for machine learning based reading order detection can be called like this:

    eynollah [GENERIC_OPTIONS] machine-based-reading-order \
      -i <single image file> | -di <directory containing image files> \
      -xml <xml file name> | -dx <directory containing xml files> \
      -o <output directory> 
    

    Documentation

    Additional documentation:

    • For using Eynollah with Docker, see docker.md.
    • For using Eynollah with OCR-D, see ocrd.md.
    • For advanced use, see use.md.
    • For model documentation and model cards, see models.md.
    • For model training or fine-tuning, see train.md.
    • For a runnable example to use with e.g. Google Colab, see eynollah_layout.ipynb.

    How to cite

    @inproceedings{hip23rezanezhad,
      title     = {Document Layout Analysis with Deep Learning and Heuristics},
      author    = {Rezanezhad, Vahid and Baierer, Konstantin and Gerber, Mike and Labusch, Kai and Neudecker, Clemens},
      booktitle = {Proceedings of the 7th International Workshop on Historical Document Imaging and Processing {HIP} 2023,
                   San José, CA, USA, August 25-26, 2023},
      publisher = {Association for Computing Machinery},
      address   = {New York, NY, USA},
      year      = {2023},
      pages     = {73--78},
      url       = {https://doi.org/10.1145/3604951.3605513}
    }