How robertknight/ocrs-models works
Main Components
• OCR Models (ocrs_models directory): This includes modules for:
• Text Detection (train_detection.py, datasets modules)
• Layout Analysis (train_layout.py, eval_layout.py, and corresponding dataset utilities)
• Text Recognition (train_rec.py)
• Evaluation processes (eval_detection.py, eval_layout.py)
• Postprocessing for predictions (postprocess.py)
• Model export functionality (export to ONNX, RTen, etc.)
• Data/Dataset Pipelines:
• Datasets support (datasets submodules: ddi100.py, hiertext.py, web_layout.py, util.py)
• Integration with open datasets such as HierText (as mentioned in README)
• Layout Scraper (layout-scraper directory):
• Main tool (layout-scraper.ts)
• Utility scripts (random-wiki-url-generator.js)
• URL lists input (url-lists directory with urls.txt)
• Supplementary Components:
• Documentation (docs folder with training instructions)
• CI/CD and configuration (Makefile, GitHub workflows, mypy.ini, pyproject.toml)
Relationships and Interactions
• Data Flow:
• The layout scraper is likely used to acquire real-world web data/HTML layouts that can be fed into the dataset pipelines.
• The dataset modules process raw data (from sources like HierText and potentially scraped data) to produce training examples.
• Training Pipeline:
• Each model (text detection, layout analysis, and text recognition) has its own training script and is fed processed dataset content.
• Postprocessing and evaluation modules interact with the models to validate outputs and fine-tune performance.
• Integration/Export:
• After training, models can be exported to different formats (ONNX, RTen) for downstream integration with the Ocrs OCR engine.
• CI/CD:
• GitHub workflows and the Makefile ensure testing, linting, and building of the system components.
Architectural Patterns and Design Principles
• Modular Design:
• Separation between data ingestion/scraping (layout-scraper) and core model training/evaluation (ocrs_models).
• Pipeline Architecture:
• Each stage—from dataset preparation, training, evaluation, to export—is isolated for clarity.
• Extensibility:
• The design allows for the addition of more datasets or model variations since different processing scripts handle each stage.
• Technology Mix:
• Python with PyTorch for model training.
• TypeScript/Node.js for the layout scraper.
• External libraries (ONNX, RTen) used for model export.