How urja4157/simplehtr works
Project Type and Purpose
• This is an open-source machine-learning tool for Handwritten Text Recognition (HTR) built on TensorFlow 2.0.
• It provides three modes—train, validate, infer—via a Python CLI (src/main.py).
• It can ingest raw IAM dataset images (words or lines), optionally convert them to LMDB for speed, train a CNN+RNN+CTC model, and run inference with multiple decoders (best-path, beam-search, word-beam-search).
Top-Level Components
A. Data Storage
• data/: raw input images (data/corpus.txt holds the vocabulary).
• IAM dataset (external), organized into img/ and gt/.
• Optional lmdb/ directory (created by create_lmdb.py) for fast image loading.
B. Model Artifacts
• model/: trained checkpoints (snapshot-*), vocabulary lists (wordCharList.txt).
C. Source Code (src/):
1. create_lmdb.py – converts raw PNGs → LMDB
2. dataloader_iam.py – loads and batches images (LMDB or PNG)
3. preprocessor.py – resizes, normalizes, augments images
4. model.py – defines CNN layers, LSTM layers, CTC loss & decoding graph
5. main.py – CLI entry point orchestrating train/validate/infer
External Dependencies
• TensorFlow 2.x for CNN/RNN/CTC
• Optional CTCWordBeamSearch library for word-beam-search decoder
• Python packages in requirements.txt
Relationships & Data Flow
1. CLI (main.py) reads command-line args (--mode, --fast, --decoder, etc.).
2. If training or validation:
– DataLoader (dataloader_iam.py) reads raw PNGs or LMDB → Tensor batches
– Preprocessor applies transforms → feeds into Model graph (model.py)
– Model trains or validates, writes checkpoints into model/
– Vocabulary extracted → data/corpus.txt and model/wordCharList.txt
3. If inference:
– DataLoader loads a single image → Preprocessor → Model → raw CTC output
– Decoder layer applies best-path or beam-search or external word-beam-search → final text
Architectural Patterns and Design Principles
• Pipeline architecture: clear separation of data ingestion, preprocessing, model definition, training, and inference.
• Modular components: each script/module implements one responsibility.
• External integration point: decoder plugin (CTCWordBeamSearch) for extensibility.
Detail
• Every script/module as its own node.
• Optional LMDB path and external decoder integration.