# githubharald/simplehtr architecture

> Architecture diagram of the GitHub repository githubharald/simplehtr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/githubharald/simplehtr
- Repository: https://github.com/githubharald/simplehtr

## Overview

This repository is a TensorFlow handwritten-text recognition system for IAM word images and multiword text lines. Its main workflow accepts a command-line inference request, preprocesses an image, runs the CNN/RNN model and CTC decoder, and reports recognized text and probability. Training and validation use IAM batches, with optional LMDB-backed image loading; training also produces model snapshots and decoder vocabulary files. The graph includes these documented capabilities. Evidence is limited to the README and sampled source excerpts, so unsampled implementation details are omitted.

Main entry points: [`src/main.py`](https://github.com/githubharald/simplehtr/blob/master/src/main.py) (Mode controller), [`src/model.py`](https://github.com/githubharald/simplehtr/blob/master/src/model.py) (CTC decoders), [`src/dataloader_iam.py`](https://github.com/githubharald/simplehtr/blob/master/src/dataloader_iam.py) (IAM batch loader), [`src/preprocessor.py`](https://github.com/githubharald/simplehtr/blob/master/src/preprocessor.py) (Image preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Run and evaluation"]
  node_main["Mode controller<br/>[main.py]"]
  node_output["Recognized text"]
  node_metrics["Validation metrics<br/>[main.py]"]
end

subgraph group_data["IAM data preparation"]
  node_preprocessor["Image preprocessing<br/>[preprocessor.py]"]
  node_line_builder["Line synthesis<br/>[preprocessor.py]"]
  node_iam_loader["IAM batch loader<br/>[dataloader_iam.py]"]
  node_iam_dataset[("IAM dataset")]
  node_lmdb_builder["LMDB creator<br/>[create_lmdb.py]"]
  node_lmdb_store[("LMDB image store")]
end

subgraph group_recognition["Recognition model"]
  node_cnn["CNN features<br/>[model.py]"]
  node_rnn["Bidirectional RNN<br/>[model.py]"]
  node_ctc["CTC loss<br/>[model.py]"]
  node_decoder["CTC decoders<br/>[model.py]"]
  node_word_decoder["Word beam package"]
end

subgraph group_artifacts["Model artifacts"]
  node_checkpoint[("Model snapshots")]
  node_vocabulary["Decoder vocabulary files"]
  node_corpus["Word corpus<br/>[corpus.txt]"]
  node_word_chars["Word character list<br/>[wordCharList.txt]"]
end

node_user(("CLI user"))

node_user -->|"selects mode"| node_main
node_main -->|"loads batches"| node_iam_loader
node_iam_loader -->|"reads IAM files"| node_iam_dataset
node_lmdb_builder -->|"writes images"| node_lmdb_store
node_iam_loader -->|"reads images"| node_lmdb_store
node_main -->|"processes images"| node_preprocessor
node_preprocessor -->|"synthesizes lines"| node_line_builder
node_main -->|"runs model"| node_cnn
node_cnn -->|"features to sequence"| node_rnn
node_rnn -->|"sequence logits"| node_ctc
node_ctc -->|"decodes logits"| node_decoder
node_decoder -.->|"optional word decoding"| node_word_decoder
node_main -->|"prints recognition"| node_output
node_main -->|"validates results"| node_metrics
node_main -->|"saves or restores"| node_checkpoint
node_main -->|"writes character list"| node_vocabulary
node_main -->|"writes training words"| node_corpus
node_decoder -->|"reads dictionary"| node_corpus
node_decoder -->|"reads character classes"| node_word_chars

click node_main "https://github.com/githubharald/simplehtr/blob/master/src/main.py"
click node_preprocessor "https://github.com/githubharald/simplehtr/blob/master/src/preprocessor.py"
click node_line_builder "https://github.com/githubharald/simplehtr/blob/master/src/preprocessor.py"
click node_iam_loader "https://github.com/githubharald/simplehtr/blob/master/src/dataloader_iam.py"
click node_lmdb_builder "https://github.com/githubharald/simplehtr/blob/master/src/create_lmdb.py"
click node_cnn "https://github.com/githubharald/simplehtr/blob/master/src/model.py"
click node_rnn "https://github.com/githubharald/simplehtr/blob/master/src/model.py"
click node_ctc "https://github.com/githubharald/simplehtr/blob/master/src/model.py"
click node_decoder "https://github.com/githubharald/simplehtr/blob/master/src/model.py"
click node_metrics "https://github.com/githubharald/simplehtr/blob/master/src/main.py"
click node_corpus "https://github.com/githubharald/simplehtr/blob/master/data/corpus.txt"
click node_word_chars "https://github.com/githubharald/simplehtr/blob/master/model/wordCharList.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_output,node_metrics,node_user toneBlue
class node_preprocessor,node_line_builder,node_iam_loader,node_iam_dataset,node_lmdb_builder,node_lmdb_store toneAmber
class node_cnn,node_rnn,node_ctc,node_decoder,node_word_decoder toneMint
class node_checkpoint,node_vocabulary,node_corpus,node_word_chars toneRose
```

## Components

### Run and evaluation

- [Mode controller](https://github.com/githubharald/simplehtr/blob/master/src/main.py): `src/main.py`
- **Recognized text**
- [Validation metrics](https://github.com/githubharald/simplehtr/blob/master/src/main.py): `src/main.py`

### IAM data preparation

- [Image preprocessing](https://github.com/githubharald/simplehtr/blob/master/src/preprocessor.py): `src/preprocessor.py`
- [Line synthesis](https://github.com/githubharald/simplehtr/blob/master/src/preprocessor.py): `src/preprocessor.py`
- [IAM batch loader](https://github.com/githubharald/simplehtr/blob/master/src/dataloader_iam.py): `src/dataloader_iam.py`
- **IAM dataset**
- [LMDB creator](https://github.com/githubharald/simplehtr/blob/master/src/create_lmdb.py): `src/create_lmdb.py`
- **LMDB image store**

### Recognition model

- [CNN features](https://github.com/githubharald/simplehtr/blob/master/src/model.py): `src/model.py`
- [Bidirectional RNN](https://github.com/githubharald/simplehtr/blob/master/src/model.py): `src/model.py`
- [CTC loss](https://github.com/githubharald/simplehtr/blob/master/src/model.py): `src/model.py`
- [CTC decoders](https://github.com/githubharald/simplehtr/blob/master/src/model.py): `src/model.py`
- **Word beam package**

### Model artifacts

- **Model snapshots**
- **Decoder vocabulary files**
- [Word corpus](https://github.com/githubharald/simplehtr/blob/master/data/corpus.txt): `data/corpus.txt`
- [Word character list](https://github.com/githubharald/simplehtr/blob/master/model/wordCharList.txt): `model/wordCharList.txt`

### Other components

- **CLI user**

## Connections

- CLI user → Mode controller: selects mode (evidence: `src/main.py`)
- Mode controller → IAM batch loader: loads batches (evidence: `src/main.py`)
- IAM batch loader → IAM dataset: reads IAM files (evidence: `src/dataloader_iam.py`)
- LMDB creator → LMDB image store: writes images (evidence: `src/create_lmdb.py`)
- IAM batch loader → LMDB image store: reads images (evidence: `src/dataloader_iam.py`)
- Mode controller → Image preprocessing: processes images (evidence: `src/main.py`)
- Image preprocessing → Line synthesis: synthesizes lines (evidence: `src/preprocessor.py`)
- Mode controller → CNN features: runs model (evidence: `src/main.py`)
- CNN features → Bidirectional RNN: features to sequence (evidence: `src/model.py`)
- Bidirectional RNN → CTC loss: sequence logits (evidence: `src/model.py`)
- CTC loss → CTC decoders: decodes logits (evidence: `src/model.py`)
- CTC decoders → Word beam package: optional word decoding (evidence: `README.md`)
- Mode controller → Recognized text: prints recognition (evidence: `src/main.py`)
- Mode controller → Validation metrics: validates results (evidence: `src/main.py`)
- Mode controller → Model snapshots: saves or restores (evidence: `src/main.py`)
- Mode controller → Decoder vocabulary files: writes character list (evidence: `src/main.py`)
- Mode controller → Word corpus: writes training words (evidence: `src/main.py`)
- CTC decoders → Word corpus: reads dictionary (evidence: `src/model.py`)
- CTC decoders → Word character list: reads character classes (evidence: `src/model.py`)
