# sagarp-c/malayalam_ocr architecture

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

- Interactive diagram: https://gitdiagram.com/sagarp-c/malayalam_ocr
- Repository: https://github.com/sagarp-c/malayalam_ocr

## Overview

This repository is a personal Malayalam handwritten-OCR workflow: scanned pages are cleaned and segmented into lines, paired with Malayalam transcriptions, used to train a Kraken model, and then transcribed. It also includes augmentation and training-log visualization. The README documents training and prediction scripts whose contents were not sampled; those capabilities are shown at the documented level, without assuming their internal calls.

Main entry points: [`train_kraken.py`](https://github.com/sagarp-c/malayalam_ocr/blob/main/train_kraken.py) (Kraken model training), [`predict.sh`](https://github.com/sagarp-c/malayalam_ocr/blob/main/predict.sh) (Document prediction), [`lines`](https://github.com/sagarp-c/malayalam_ocr/tree/main/lines) (Line images), [`vari.py`](https://github.com/sagarp-c/malayalam_ocr/blob/main/vari.py) (Image augmentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_image_prep["Image preparation"]
  node_raw_scans["Scanned pages"]
  node_preprocess["Image preprocessing<br/>[preprocess.py]"]
  node_processed_pages["Processed pages"]
  node_segmentation["Line segmentation<br/>[segment_lines.py]"]
  node_line_images["Line images"]
  node_manual_cropping["Manual line cropping"]
end

subgraph group_transcription_data["Transcription data"]
  node_ground_truth["Transcriptions<br/>[ground_truth.txt]"]
  node_split_transcriptions["Split transcriptions"]
  node_line_transcriptions["Line transcription files"]
  node_augmentation["Image augmentation<br/>[vari.py]"]
  node_augmented_data["Augmented training pairs"]
end

subgraph group_ocr["OCR training and use"]
  node_training["Kraken model training<br/>[train_kraken.py]"]
  node_training_script["Training entry script<br/>[train.sh]"]
  node_model["OCR model output"]
  node_prediction_script["Document prediction<br/>[predict.sh]"]
  node_digitized_text["Digitized story"]
end

subgraph group_analysis["Training analysis"]
  node_log_plotter["Training log plots<br/>[plot_only.py]"]
  node_training_logs["Training logs<br/>[training_log.txt]"]
end

node_user(("Project user"))

node_user -->|"provides scans"| node_raw_scans
node_raw_scans -->|"reads scans"| node_preprocess
node_preprocess -->|"writes pages"| node_processed_pages
node_processed_pages -->|"segments pages"| node_segmentation
node_segmentation -->|"writes lines"| node_line_images
node_user -->|"crops lines"| node_manual_cropping
node_manual_cropping -.->|"creates lines"| node_line_images
node_user -->|"writes transcriptions"| node_ground_truth
node_ground_truth -->|"reads pairs"| node_split_transcriptions
node_split_transcriptions -->|"writes text files"| node_line_transcriptions
node_line_images -.->|"reads images"| node_augmentation
node_line_transcriptions -.->|"reads text"| node_augmentation
node_augmentation -->|"writes pairs"| node_augmented_data
node_augmented_data -->|"validates training pairs"| node_training
node_training_script -.->|"runs training"| node_training
node_training -.->|"writes model"| node_model
node_user -->|"requests transcription"| node_prediction_script
node_prediction_script -.->|"uses trained model"| node_model
node_prediction_script -->|"transcribes pages"| node_digitized_text
node_training -->|"writes logs"| node_training_logs
node_training_logs -->|"reads metrics"| node_log_plotter

click node_raw_scans "https://github.com/sagarp-c/malayalam_ocr/tree/main/images/raw"
click node_preprocess "https://github.com/sagarp-c/malayalam_ocr/blob/main/preprocess.py"
click node_processed_pages "https://github.com/sagarp-c/malayalam_ocr/tree/main/images/processed"
click node_segmentation "https://github.com/sagarp-c/malayalam_ocr/blob/main/segment_lines.py"
click node_line_images "https://github.com/sagarp-c/malayalam_ocr/tree/main/lines"
click node_manual_cropping "https://github.com/sagarp-c/malayalam_ocr/tree/main/lines"
click node_ground_truth "https://github.com/sagarp-c/malayalam_ocr/blob/main/ground_truth.txt"
click node_split_transcriptions "https://github.com/sagarp-c/malayalam_ocr/blob/main/split_ground_truth.py"
click node_line_transcriptions "https://github.com/sagarp-c/malayalam_ocr/tree/main/lines"
click node_augmentation "https://github.com/sagarp-c/malayalam_ocr/blob/main/vari.py"
click node_augmented_data "https://github.com/sagarp-c/malayalam_ocr/tree/main/lines"
click node_training "https://github.com/sagarp-c/malayalam_ocr/blob/main/train_kraken.py"
click node_training_script "https://github.com/sagarp-c/malayalam_ocr/blob/main/train.sh"
click node_model "https://github.com/sagarp-c/malayalam_ocr/tree/main/model_output"
click node_prediction_script "https://github.com/sagarp-c/malayalam_ocr/blob/main/predict.sh"
click node_log_plotter "https://github.com/sagarp-c/malayalam_ocr/blob/main/plot_only.py"
click node_training_logs "https://github.com/sagarp-c/malayalam_ocr/blob/main/model_output/training_log.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_raw_scans,node_preprocess,node_processed_pages,node_segmentation,node_line_images,node_manual_cropping,node_user toneBlue
class node_ground_truth,node_split_transcriptions,node_line_transcriptions,node_augmentation,node_augmented_data toneAmber
class node_training,node_training_script,node_model,node_prediction_script,node_digitized_text toneMint
class node_log_plotter,node_training_logs toneRose
```

## Components

### Image preparation

- [Scanned pages](https://github.com/sagarp-c/malayalam_ocr/tree/main/images/raw): `images/raw`
- [Image preprocessing](https://github.com/sagarp-c/malayalam_ocr/blob/main/preprocess.py): `preprocess.py`
- [Processed pages](https://github.com/sagarp-c/malayalam_ocr/tree/main/images/processed): `images/processed`
- [Line segmentation](https://github.com/sagarp-c/malayalam_ocr/blob/main/segment_lines.py): `segment_lines.py`
- [Line images](https://github.com/sagarp-c/malayalam_ocr/tree/main/lines): `lines`
- [Manual line cropping](https://github.com/sagarp-c/malayalam_ocr/tree/main/lines): `lines`

### Transcription data

- [Transcriptions](https://github.com/sagarp-c/malayalam_ocr/blob/main/ground_truth.txt): `ground_truth.txt`
- [Split transcriptions](https://github.com/sagarp-c/malayalam_ocr/blob/main/split_ground_truth.py): `split_ground_truth.py`
- [Line transcription files](https://github.com/sagarp-c/malayalam_ocr/tree/main/lines): `lines`
- [Image augmentation](https://github.com/sagarp-c/malayalam_ocr/blob/main/vari.py): `vari.py`
- [Augmented training pairs](https://github.com/sagarp-c/malayalam_ocr/tree/main/lines): `lines`

### OCR training and use

- [Kraken model training](https://github.com/sagarp-c/malayalam_ocr/blob/main/train_kraken.py): `train_kraken.py`
- [Training entry script](https://github.com/sagarp-c/malayalam_ocr/blob/main/train.sh): `train.sh`
- [OCR model output](https://github.com/sagarp-c/malayalam_ocr/tree/main/model_output): `model_output`
- [Document prediction](https://github.com/sagarp-c/malayalam_ocr/blob/main/predict.sh): `predict.sh`
- **Digitized story**

### Training analysis

- [Training log plots](https://github.com/sagarp-c/malayalam_ocr/blob/main/plot_only.py): `plot_only.py`
- [Training logs](https://github.com/sagarp-c/malayalam_ocr/blob/main/model_output/training_log.txt): `model_output/training_log.txt`

### Other components

- **Project user**

## Connections

- Project user → Scanned pages: provides scans (evidence: `README.md`)
- Scanned pages → Image preprocessing: reads scans (evidence: `preprocess.py`)
- Image preprocessing → Processed pages: writes pages (evidence: `preprocess.py`)
- Processed pages → Line segmentation: segments pages (evidence: `segment_lines.py`)
- Line segmentation → Line images: writes lines (evidence: `segment_lines.py`)
- Project user → Manual line cropping: crops lines (evidence: `README.md`)
- Manual line cropping → Line images: creates lines
- Project user → Transcriptions: writes transcriptions (evidence: `README.md`)
- Transcriptions → Split transcriptions: reads pairs (evidence: `split_ground_truth.py`)
- Split transcriptions → Line transcription files: writes text files (evidence: `split_ground_truth.py`)
- Line images → Image augmentation: reads images
- Line transcription files → Image augmentation: reads text
- Image augmentation → Augmented training pairs: writes pairs (evidence: `vari.py`)
- Augmented training pairs → Kraken model training: validates training pairs (evidence: `train_kraken.py`)
- Training entry script → Kraken model training: runs training
- Kraken model training → OCR model output: writes model
- Project user → Document prediction: requests transcription (evidence: `README.md`)
- Document prediction → OCR model output: uses trained model
- Document prediction → Digitized story: transcribes pages (evidence: `README.md`)
- Kraken model training → Training logs: writes logs (evidence: `train_kraken.py`)
- Training logs → Training log plots: reads metrics (evidence: `plot_only.py`)
