# nnaajjeebb12/hw-recog architecture

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

- Interactive diagram: https://gitdiagram.com/nnaajjeebb12/hw-recog
- Repository: https://github.com/nnaajjeebb12/hw-recog

## Overview

This repository is a small TrOCR-based tool for training a text recognizer on labeled image crops and using it to transcribe new images. The main workflow is: prepare image/label data, train and validate a model, then run prediction to produce a CSV. Training also supports held-out testing and optional image augmentation; prediction supports pattern-constrained retries. The README documents these capabilities, while the source excerpts show their implementation is concentrated in two scripts. Full-page cropping is explicitly outside the product.

Main entry points: [`train.py`](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py) (Model fine-tuning), [`predict.py`](https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py) (TextReader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Training"]
  node_prep["Data preparation<br/>[train.py]"]
  node_cache[("Image cache<br/>[train.py]")]
  node_augmentation["Image augmentation<br/>[train.py]"]
  node_finetune["Model fine-tuning<br/>[train.py]"]
  node_validation["Validation and selection<br/>[train.py]"]
  node_testing["Held-out testing<br/>[train.py]"]
  node_trained_model["Saved model<br/>[train.py]"]
end

subgraph group_inference["Inference"]
  node_enumerate["Image discovery<br/>[predict.py]"]
  node_reader["TextReader<br/>[predict.py]"]
  node_pattern["Pattern retry<br/>[predict.py]"]
  node_predictions["Prediction CSV<br/>[predict.py]"]
end

subgraph group_integrations["Model integration"]
  node_base_model["Hugging Face model"]
end

node_user(("User"))
node_dataset["Labeled image data"]
node_image_folder["Input image folder"]

node_user -->|"provides"| node_dataset
node_dataset -->|"loads labels"| node_prep
node_prep -->|"caches images"| node_cache
node_prep -->|"supplies splits"| node_finetune
node_augmentation -->|"augments batches"| node_finetune
node_cache -->|"loads cached images"| node_finetune
node_finetune -->|"scores each epoch"| node_validation
node_validation -->|"saves best"| node_trained_model
node_finetune -->|"scores test set"| node_testing
node_base_model -->|"initializes from"| node_finetune
node_user -->|"provides images"| node_image_folder
node_image_folder -->|"scans files"| node_enumerate
node_trained_model -->|"loads model"| node_reader
node_enumerate -->|"batches images"| node_reader
node_reader -->|"retries mismatches"| node_pattern
node_reader -->|"writes results"| node_predictions
node_pattern -->|"updates results"| node_predictions
node_predictions -->|"returns readings"| node_user

click node_prep "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_cache "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_augmentation "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_finetune "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_validation "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_testing "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_trained_model "https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py"
click node_enumerate "https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py"
click node_reader "https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py"
click node_pattern "https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py"
click node_predictions "https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py"

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_prep,node_cache,node_augmentation,node_finetune,node_validation,node_testing,node_trained_model,node_user toneBlue
class node_enumerate,node_reader,node_pattern,node_predictions toneAmber
class node_base_model toneMint
class node_dataset,node_image_folder toneIndigo
```

## Components

### Training

- [Data preparation](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`
- [Image cache](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`
- [Image augmentation](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`
- [Model fine-tuning](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`
- [Validation and selection](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`
- [Held-out testing](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`
- [Saved model](https://github.com/nnaajjeebb12/hw-recog/blob/main/train.py): `train.py`

### Inference

- [Image discovery](https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py): `predict.py`
- [TextReader](https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py): `predict.py`
- [Pattern retry](https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py): `predict.py`
- [Prediction CSV](https://github.com/nnaajjeebb12/hw-recog/blob/main/predict.py): `predict.py`

### Model integration

- **Hugging Face model**

### Other components

- **User**
- **Labeled image data**
- **Input image folder**

## Connections

- User → Labeled image data: provides (evidence: `README.md`)
- Labeled image data → Data preparation: loads labels (evidence: `README.md`)
- Data preparation → Image cache: caches images (evidence: `README.md`)
- Data preparation → Model fine-tuning: supplies splits (evidence: `README.md`)
- Image augmentation → Model fine-tuning: augments batches (evidence: `train.py`)
- Image cache → Model fine-tuning: loads cached images (evidence: `train.py`)
- Model fine-tuning → Validation and selection: scores each epoch (evidence: `README.md`)
- Validation and selection → Saved model: saves best (evidence: `README.md`)
- Model fine-tuning → Held-out testing: scores test set (evidence: `README.md`)
- Hugging Face model → Model fine-tuning: initializes from (evidence: `README.md`)
- User → Input image folder: provides images (evidence: `README.md`)
- Input image folder → Image discovery: scans files (evidence: `predict.py`)
- Saved model → TextReader: loads model (evidence: `predict.py`)
- Image discovery → TextReader: batches images (evidence: `predict.py`)
- TextReader → Pattern retry: retries mismatches (evidence: `predict.py`)
- TextReader → Prediction CSV: writes results (evidence: `predict.py`)
- Pattern retry → Prediction CSV: updates results (evidence: `predict.py`)
- Prediction CSV → User: returns readings (evidence: `README.md`)
