How rsommerfeld/trocr works
This repository is a small TrOCR-based handwritten-character recognition application. Its user workflow starts at the CLI (or the exported predictor interface), loads a processor and model, prepares images, then predicts text and confidence, validates predictions against labels, or trains and saves a model. The graph also preserves dataset preparation, shared run context, and configurable paths and training parameters. Edges reflect the shown calls and documented modes; the configured checkpoint directory and Hugging Face model source are runtime locations, not source files in the tree.
Main entry points: main.py Workflow setup · dataset.py Labeled image dataset · util.py Model and processor loading · scripts.py Model training
Components 18
User interfaces
- CLI commands
src/cli.py - Predictor API
src/main.py
Datasets and labels
- Labeled image dataset
src/dataset.py - In-memory images
src/dataset.py - Training images
train - Validation images
val - Image labels CSV
gt/labels.csv
Recognition workflows
- Workflow setup
src/main.py - Training context
src/context.py - Prediction and confidence
src/scripts.py - Validation scoring
src/scripts.py - Model training
src/scripts.py
Configuration and models
- Model and processor loading
src/util.py - Data and checkpoint paths
src/configs/paths.py - Training settings
src/configs/constants.py - Local model checkpoint
Other components
- User
- Hugging Face models
Connections 29
- User → CLI commands: runs commands
- CLI commands → Workflow setup: dispatches workflows
src/cli.py - User → Predictor API: calls API
README.md - Workflow setup → Model and processor loading: loads models
src/main.py - Workflow setup → Labeled image dataset: creates datasets
src/main.py - Workflow setup → In-memory images: prepares images
src/main.py - Workflow setup → Training context: assembles context
src/main.py - Workflow setup → Model training: starts training
src/main.py - Workflow setup → Validation scoring: starts validation
src/main.py - Workflow setup → Prediction and confidence: predicts images
src/main.py - Workflow setup → Local model checkpoint: saves model
src/main.py - Labeled image dataset → Training images: reads images
src/dataset.py - Labeled image dataset → Validation images: reads images
src/dataset.py - Labeled image dataset → Image labels CSV: loads labels
src/dataset.py - Validation scoring → Training context: uses validation data
src/scripts.py - Validation scoring → Prediction and confidence: requests predictions
src/scripts.py - Model training → Training context: uses training data
src/scripts.py - Model training → Validation scoring: scores epochs
src/scripts.py - Model and processor loading → Data and checkpoint paths: reads model paths
src/util.py - Model and processor loading → Training settings: selects device
src/util.py - Model and processor loading → Local model checkpoint: loads local model
src/util.py - Model and processor loading → Hugging Face models: loads pretrained model
src/util.py - Labeled image dataset → Data and checkpoint paths: uses data paths
src/dataset.py - Labeled image dataset → Training settings: uses padding settings
src/dataset.py - Prediction and confidence → Training settings: uses device
src/scripts.py - Model training → Training settings: uses training parameters
src/scripts.py - Predictor API → In-memory images: builds image batches
src/main.py - Predictor API → Prediction and confidence: requests predictions
src/main.py - Predictor API → Model and processor loading: loads processor and model
src/main.py