# tanhdz228/od-ocr-system-for-engineering-drawings architecture

> Architecture diagram of the GitHub repository tanhdz228/od-ocr-system-for-engineering-drawings, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanhdz228/od-ocr-system-for-engineering-drawings
- Repository: https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings

## Overview

ODOCR accepts engineering drawings through either a command-line batch runner or a Gradio demo, then detects PartDrawing, Note, and Table regions and produces crops, OCR content, JSON, and visualizations. Detection and the two OCR paths are distinct runtime stages; table extraction includes line-based structure detection and fallback methods. The README also documents a separate model-development workflow for dataset preparation, augmentation, training, cross-validation, and evaluation. Some integrations and training links are documented but their source was not sampled, so those edges cite the README.

Main entry points: [`src/pipeline.py`](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/pipeline.py) (Image pipeline), [`src/ocr/table_ocr.py`](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/table_ocr.py) (Table OCR), [`scripts/training/train_cv.py`](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/train_cv.py) (Cross-validation), [`scripts/training/prepare_dataset.py`](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/prepare_dataset.py) (Dataset conversion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User Entry"]
  node_gradio["Web demo<br/>[app.py]"]
  node_cli["CLI runner<br/>[inference.py]"]
end

subgraph group_runtime["Inference Pipeline"]
  node_pipeline["Image pipeline<br/>[pipeline.py]"]
  node_detector["Region detector<br/>[detector.py]"]
  node_outputs["JSON and visualization<br/>[pipeline.py]"]
end

subgraph group_extraction["OCR Extraction"]
  node_noteocr["Note OCR<br/>[note_ocr.py]"]
  node_tableocr["Table OCR<br/>[table_ocr.py]"]
  node_structure["Table structure<br/>[table_structure.py]"]
  node_ocrengines["OCR engines"]
  node_tatr["Table Transformer"]
end

subgraph group_development["Model Development"]
  node_annotations["COCO annotations<br/>[coco_all.json]"]
  node_splits["CV split generation"]
  node_prepare["Dataset conversion<br/>[prepare_dataset.py]"]
  node_augment["Dataset augmentation<br/>[augment_dataset.py]"]
  node_train["Model training<br/>[train.py]"]
  node_traincv["Cross-validation<br/>[train_cv.py]"]
  node_evaluate["Model evaluation<br/>[evaluate.py]"]
end

node_user(("Drawing user"))

node_user -->|"uploads drawing"| node_gradio
node_user -->|"provides image"| node_cli
node_gradio -->|"runs inference"| node_pipeline
node_cli -->|"processes images"| node_pipeline
node_pipeline -->|"detects regions"| node_detector
node_pipeline -->|"routes Note crops"| node_noteocr
node_pipeline -->|"routes Table crops"| node_tableocr
node_pipeline -->|"writes results"| node_outputs
node_pipeline -->|"draws boxes"| node_detector
node_tableocr -->|"detects grid"| node_structure
node_noteocr -.->|"recognizes text"| node_ocrengines
node_tableocr -.->|"reads cells"| node_ocrengines
node_tableocr -.->|"fallback recognition"| node_tatr
node_annotations -->|"creates folds"| node_splits
node_annotations -->|"converts labels"| node_prepare
node_splits -->|"supplies fold splits"| node_traincv
node_prepare -->|"feeds training images"| node_augment
node_augment -->|"provides augmented data"| node_train
node_train -->|"evaluates weights"| node_evaluate
node_traincv -->|"prepares fold data"| node_prepare
node_traincv -->|"optionally augments"| node_augment
node_traincv -->|"runs fold training"| node_train

click node_gradio "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/app.py"
click node_cli "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/inference.py"
click node_pipeline "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/pipeline.py"
click node_detector "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/detection/detector.py"
click node_outputs "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/pipeline.py"
click node_noteocr "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/note_ocr.py"
click node_tableocr "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/table_ocr.py"
click node_structure "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/table_structure.py"
click node_annotations "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/data/annotations/coco_all.json"
click node_splits "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/preprocessing/create_cv_splits.py"
click node_prepare "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/prepare_dataset.py"
click node_augment "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/preprocessing/augment_dataset.py"
click node_train "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/train.py"
click node_traincv "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/train_cv.py"
click node_evaluate "https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/evaluate.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_gradio,node_cli,node_user toneBlue
class node_pipeline,node_detector,node_outputs toneAmber
class node_noteocr,node_tableocr,node_structure,node_ocrengines,node_tatr toneMint
class node_annotations,node_splits,node_prepare,node_augment,node_train,node_traincv,node_evaluate toneRose
```

## Components

### User Entry

- [Web demo](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/app.py): `app.py`
- [CLI runner](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/inference.py): `inference.py`

### Inference Pipeline

- [Image pipeline](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/pipeline.py): `src/pipeline.py`
- [Region detector](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/detection/detector.py): `src/detection/detector.py`
- [JSON and visualization](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/pipeline.py): `src/pipeline.py`

### OCR Extraction

- [Note OCR](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/note_ocr.py): `src/ocr/note_ocr.py`
- [Table OCR](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/table_ocr.py): `src/ocr/table_ocr.py`
- [Table structure](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/src/ocr/table_structure.py): `src/ocr/table_structure.py`
- **OCR engines**
- **Table Transformer**

### Model Development

- [COCO annotations](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/data/annotations/coco_all.json): `data/annotations/coco_all.json`
- [CV split generation](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/preprocessing/create_cv_splits.py): `scripts/preprocessing/create_cv_splits.py`
- [Dataset conversion](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/prepare_dataset.py): `scripts/training/prepare_dataset.py`
- [Dataset augmentation](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/preprocessing/augment_dataset.py): `scripts/preprocessing/augment_dataset.py`
- [Model training](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/train.py): `scripts/training/train.py`
- [Cross-validation](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/train_cv.py): `scripts/training/train_cv.py`
- [Model evaluation](https://github.com/tanhdz228/od-ocr-system-for-engineering-drawings/blob/main/scripts/training/evaluate.py): `scripts/training/evaluate.py`

### Other components

- **Drawing user**

## Connections

- Drawing user → Web demo: uploads drawing (evidence: `README.md`)
- Drawing user → CLI runner: provides image (evidence: `README.md`)
- Web demo → Image pipeline: runs inference (evidence: `app.py`)
- CLI runner → Image pipeline: processes images (evidence: `inference.py`)
- Image pipeline → Region detector: detects regions (evidence: `src/pipeline.py`)
- Image pipeline → Note OCR: routes Note crops (evidence: `src/pipeline.py`)
- Image pipeline → Table OCR: routes Table crops (evidence: `src/pipeline.py`)
- Image pipeline → JSON and visualization: writes results (evidence: `src/pipeline.py`)
- Image pipeline → Region detector: draws boxes (evidence: `src/pipeline.py`)
- Table OCR → Table structure: detects grid (evidence: `src/ocr/table_ocr.py`)
- Note OCR → OCR engines: recognizes text (evidence: `README.md`)
- Table OCR → OCR engines: reads cells (evidence: `README.md`)
- Table OCR → Table Transformer: fallback recognition (evidence: `README.md`)
- COCO annotations → CV split generation: creates folds (evidence: `README.md`)
- COCO annotations → Dataset conversion: converts labels (evidence: `README.md`)
- CV split generation → Cross-validation: supplies fold splits (evidence: `README.md`)
- Dataset conversion → Dataset augmentation: feeds training images (evidence: `README.md`)
- Dataset augmentation → Model training: provides augmented data (evidence: `README.md`)
- Model training → Model evaluation: evaluates weights (evidence: `README.md`)
- Cross-validation → Dataset conversion: prepares fold data (evidence: `README.md`)
- Cross-validation → Dataset augmentation: optionally augments (evidence: `README.md`)
- Cross-validation → Model training: runs fold training (evidence: `README.md`)
