Merge pull request #4 from Ismat-Samadov/claude/create-word-presentation-01BDWVNs3uJTgE7g3BbTYcVC
Browse files
Handwriting_Recognition_Presentation.docx
ADDED
|
Binary file (42.1 kB). View file
|
|
|
create_presentation.py
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script to create a Word document presentation for the Handwriting Recognition project.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from docx import Document
|
| 7 |
+
from docx.shared import Inches, Pt, RGBColor
|
| 8 |
+
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 9 |
+
from docx.enum.style import WD_STYLE_TYPE
|
| 10 |
+
from docx.enum.table import WD_TABLE_ALIGNMENT
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
def create_presentation():
|
| 14 |
+
doc = Document()
|
| 15 |
+
|
| 16 |
+
# Set document margins
|
| 17 |
+
sections = doc.sections
|
| 18 |
+
for section in sections:
|
| 19 |
+
section.top_margin = Inches(1)
|
| 20 |
+
section.bottom_margin = Inches(1)
|
| 21 |
+
section.left_margin = Inches(1)
|
| 22 |
+
section.right_margin = Inches(1)
|
| 23 |
+
|
| 24 |
+
# ============== TITLE PAGE ==============
|
| 25 |
+
# Add some spacing before title
|
| 26 |
+
for _ in range(4):
|
| 27 |
+
doc.add_paragraph()
|
| 28 |
+
|
| 29 |
+
# Title
|
| 30 |
+
title = doc.add_paragraph()
|
| 31 |
+
title_run = title.add_run("Handwriting Recognition")
|
| 32 |
+
title_run.bold = True
|
| 33 |
+
title_run.font.size = Pt(36)
|
| 34 |
+
title_run.font.color.rgb = RGBColor(0, 51, 102)
|
| 35 |
+
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 36 |
+
|
| 37 |
+
# Subtitle
|
| 38 |
+
subtitle = doc.add_paragraph()
|
| 39 |
+
sub_run = subtitle.add_run("Deep Learning OCR with CNN-BiLSTM-CTC Architecture")
|
| 40 |
+
sub_run.font.size = Pt(18)
|
| 41 |
+
sub_run.font.color.rgb = RGBColor(102, 102, 102)
|
| 42 |
+
subtitle.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 43 |
+
|
| 44 |
+
doc.add_paragraph()
|
| 45 |
+
doc.add_paragraph()
|
| 46 |
+
|
| 47 |
+
# Key stats box
|
| 48 |
+
stats_para = doc.add_paragraph()
|
| 49 |
+
stats_para.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 50 |
+
stats_run = stats_para.add_run("87% Character Accuracy | 9.1M Parameters | 20 min Training")
|
| 51 |
+
stats_run.font.size = Pt(14)
|
| 52 |
+
stats_run.font.color.rgb = RGBColor(0, 128, 0)
|
| 53 |
+
stats_run.bold = True
|
| 54 |
+
|
| 55 |
+
doc.add_paragraph()
|
| 56 |
+
doc.add_paragraph()
|
| 57 |
+
|
| 58 |
+
# Technology badges
|
| 59 |
+
tech_para = doc.add_paragraph()
|
| 60 |
+
tech_para.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 61 |
+
tech_run = tech_para.add_run("PyTorch | Python 3.12 | Hugging Face | Google Colab")
|
| 62 |
+
tech_run.font.size = Pt(12)
|
| 63 |
+
tech_run.italic = True
|
| 64 |
+
|
| 65 |
+
# Page break
|
| 66 |
+
doc.add_page_break()
|
| 67 |
+
|
| 68 |
+
# ============== TABLE OF CONTENTS ==============
|
| 69 |
+
toc_title = doc.add_heading("Table of Contents", level=1)
|
| 70 |
+
|
| 71 |
+
toc_items = [
|
| 72 |
+
"1. Executive Summary",
|
| 73 |
+
"2. Project Overview",
|
| 74 |
+
"3. Technology Stack",
|
| 75 |
+
"4. Model Architecture",
|
| 76 |
+
"5. Dataset Analysis",
|
| 77 |
+
"6. Training Results",
|
| 78 |
+
"7. Performance Metrics",
|
| 79 |
+
"8. Quick Start Guide",
|
| 80 |
+
"9. Use Cases & Applications",
|
| 81 |
+
"10. Future Improvements",
|
| 82 |
+
"11. Conclusion"
|
| 83 |
+
]
|
| 84 |
+
|
| 85 |
+
for item in toc_items:
|
| 86 |
+
p = doc.add_paragraph(item)
|
| 87 |
+
p.paragraph_format.space_after = Pt(8)
|
| 88 |
+
|
| 89 |
+
doc.add_page_break()
|
| 90 |
+
|
| 91 |
+
# ============== EXECUTIVE SUMMARY ==============
|
| 92 |
+
doc.add_heading("1. Executive Summary", level=1)
|
| 93 |
+
|
| 94 |
+
exec_summary = """This project implements a state-of-the-art handwriting recognition system using deep learning. The system converts images of handwritten text into digital text with 87% character-level accuracy.
|
| 95 |
+
|
| 96 |
+
Key Achievements:
|
| 97 |
+
"""
|
| 98 |
+
doc.add_paragraph(exec_summary)
|
| 99 |
+
|
| 100 |
+
achievements = [
|
| 101 |
+
("Character Accuracy", "87% (CER: 12.95%)"),
|
| 102 |
+
("Word Accuracy", "57.5% (WER: 42.47%)"),
|
| 103 |
+
("Training Samples", "10,373 from IAM Database"),
|
| 104 |
+
("Model Size", "105MB (9.1M parameters)"),
|
| 105 |
+
("Training Time", "~20 minutes on T4 GPU"),
|
| 106 |
+
("Inference Speed", "50-100ms per image (GPU)")
|
| 107 |
+
]
|
| 108 |
+
|
| 109 |
+
table = doc.add_table(rows=1, cols=2)
|
| 110 |
+
table.style = 'Table Grid'
|
| 111 |
+
hdr_cells = table.rows[0].cells
|
| 112 |
+
hdr_cells[0].text = 'Metric'
|
| 113 |
+
hdr_cells[1].text = 'Value'
|
| 114 |
+
for cell in hdr_cells:
|
| 115 |
+
cell.paragraphs[0].runs[0].bold = True
|
| 116 |
+
|
| 117 |
+
for metric, value in achievements:
|
| 118 |
+
row = table.add_row().cells
|
| 119 |
+
row[0].text = metric
|
| 120 |
+
row[1].text = value
|
| 121 |
+
|
| 122 |
+
doc.add_paragraph()
|
| 123 |
+
doc.add_paragraph("The model is production-ready and available on Hugging Face Hub for immediate deployment.")
|
| 124 |
+
|
| 125 |
+
doc.add_page_break()
|
| 126 |
+
|
| 127 |
+
# ============== PROJECT OVERVIEW ==============
|
| 128 |
+
doc.add_heading("2. Project Overview", level=1)
|
| 129 |
+
|
| 130 |
+
doc.add_heading("Purpose", level=2)
|
| 131 |
+
doc.add_paragraph("The primary goal of this project is to build an end-to-end Optical Character Recognition (OCR) system that can automatically convert handwritten text images into digital text.")
|
| 132 |
+
|
| 133 |
+
doc.add_heading("Problem Statement", level=2)
|
| 134 |
+
doc.add_paragraph("""Traditional OCR systems struggle with handwritten text due to:
|
| 135 |
+
- High variability in writing styles
|
| 136 |
+
- Inconsistent character spacing
|
| 137 |
+
- Connected/cursive letters
|
| 138 |
+
- Variable image quality
|
| 139 |
+
|
| 140 |
+
This project addresses these challenges using modern deep learning techniques.""")
|
| 141 |
+
|
| 142 |
+
doc.add_heading("Solution Approach", level=2)
|
| 143 |
+
doc.add_paragraph("We implement a CNN-BiLSTM-CTC architecture that:")
|
| 144 |
+
|
| 145 |
+
bullet_points = [
|
| 146 |
+
"Extracts visual features using Convolutional Neural Networks (CNN)",
|
| 147 |
+
"Models sequential dependencies with Bidirectional LSTM",
|
| 148 |
+
"Uses CTC Loss for alignment-free training",
|
| 149 |
+
"Requires only text labels (no character position annotations)"
|
| 150 |
+
]
|
| 151 |
+
|
| 152 |
+
for point in bullet_points:
|
| 153 |
+
p = doc.add_paragraph(point, style='List Bullet')
|
| 154 |
+
|
| 155 |
+
doc.add_page_break()
|
| 156 |
+
|
| 157 |
+
# ============== TECHNOLOGY STACK ==============
|
| 158 |
+
doc.add_heading("3. Technology Stack", level=1)
|
| 159 |
+
|
| 160 |
+
doc.add_heading("Core Technologies", level=2)
|
| 161 |
+
|
| 162 |
+
tech_table = doc.add_table(rows=1, cols=3)
|
| 163 |
+
tech_table.style = 'Table Grid'
|
| 164 |
+
hdr = tech_table.rows[0].cells
|
| 165 |
+
hdr[0].text = 'Technology'
|
| 166 |
+
hdr[1].text = 'Version'
|
| 167 |
+
hdr[2].text = 'Purpose'
|
| 168 |
+
for cell in hdr:
|
| 169 |
+
cell.paragraphs[0].runs[0].bold = True
|
| 170 |
+
|
| 171 |
+
technologies = [
|
| 172 |
+
("Python", "3.12+", "Primary programming language"),
|
| 173 |
+
("PyTorch", "2.0+", "Deep learning framework"),
|
| 174 |
+
("Hugging Face Datasets", "2.14+", "Dataset loading"),
|
| 175 |
+
("Pillow", "9.5+", "Image processing"),
|
| 176 |
+
("NumPy", "1.24+", "Numerical computations"),
|
| 177 |
+
("Matplotlib", "3.7+", "Visualization"),
|
| 178 |
+
("Seaborn", "0.13+", "Statistical plots"),
|
| 179 |
+
("jiwer", "3.0+", "CER/WER metrics"),
|
| 180 |
+
("Jupyter", "1.0+", "Development environment")
|
| 181 |
+
]
|
| 182 |
+
|
| 183 |
+
for tech, ver, purpose in technologies:
|
| 184 |
+
row = tech_table.add_row().cells
|
| 185 |
+
row[0].text = tech
|
| 186 |
+
row[1].text = ver
|
| 187 |
+
row[2].text = purpose
|
| 188 |
+
|
| 189 |
+
doc.add_paragraph()
|
| 190 |
+
|
| 191 |
+
doc.add_heading("Deployment Platforms", level=2)
|
| 192 |
+
platforms = [
|
| 193 |
+
"Google Colab: Free GPU training (T4/A100)",
|
| 194 |
+
"Hugging Face Hub: Model hosting and distribution",
|
| 195 |
+
"Local GPU: For production deployment"
|
| 196 |
+
]
|
| 197 |
+
for p in platforms:
|
| 198 |
+
doc.add_paragraph(p, style='List Bullet')
|
| 199 |
+
|
| 200 |
+
doc.add_page_break()
|
| 201 |
+
|
| 202 |
+
# ============== MODEL ARCHITECTURE ==============
|
| 203 |
+
doc.add_heading("4. Model Architecture", level=1)
|
| 204 |
+
|
| 205 |
+
doc.add_heading("Architecture Overview: CNN-BiLSTM-CTC", level=2)
|
| 206 |
+
|
| 207 |
+
arch_desc = """The model follows a proven architecture for sequence-to-sequence text recognition:
|
| 208 |
+
|
| 209 |
+
1. CNN Feature Extractor (7 blocks)
|
| 210 |
+
- Input: Grayscale image [Batch, 1, 128, Width]
|
| 211 |
+
- Output: Feature maps [Batch, 512, 7, Width/4]
|
| 212 |
+
- Uses progressive channel growth: 1→64→128→256→512
|
| 213 |
+
- Asymmetric pooling preserves horizontal resolution
|
| 214 |
+
|
| 215 |
+
2. Sequence Mapping Layer
|
| 216 |
+
- Reshapes CNN output to sequence format
|
| 217 |
+
- Linear projection: 3584 → 256 dimensions
|
| 218 |
+
|
| 219 |
+
3. Bidirectional LSTM (2 layers)
|
| 220 |
+
- Hidden size: 256 per direction
|
| 221 |
+
- Output: 512 dimensions (forward + backward)
|
| 222 |
+
- Dropout: 0.3 for regularization
|
| 223 |
+
|
| 224 |
+
4. CTC Output Layer
|
| 225 |
+
- Linear: 512 → 75 (74 characters + blank token)
|
| 226 |
+
- LogSoftmax for probability distribution
|
| 227 |
+
"""
|
| 228 |
+
doc.add_paragraph(arch_desc)
|
| 229 |
+
|
| 230 |
+
doc.add_heading("Model Parameters", level=2)
|
| 231 |
+
|
| 232 |
+
params_table = doc.add_table(rows=1, cols=2)
|
| 233 |
+
params_table.style = 'Table Grid'
|
| 234 |
+
hdr = params_table.rows[0].cells
|
| 235 |
+
hdr[0].text = 'Component'
|
| 236 |
+
hdr[1].text = 'Parameters'
|
| 237 |
+
for cell in hdr:
|
| 238 |
+
cell.paragraphs[0].runs[0].bold = True
|
| 239 |
+
|
| 240 |
+
params = [
|
| 241 |
+
("CNN Feature Extractor", "~4.5M"),
|
| 242 |
+
("Sequence Mapper", "~0.9M"),
|
| 243 |
+
("BiLSTM Layers", "~3.2M"),
|
| 244 |
+
("Output Layer", "~0.5M"),
|
| 245 |
+
("Total", "9,139,147 (9.1M)")
|
| 246 |
+
]
|
| 247 |
+
|
| 248 |
+
for comp, param in params:
|
| 249 |
+
row = params_table.add_row().cells
|
| 250 |
+
row[0].text = comp
|
| 251 |
+
row[1].text = param
|
| 252 |
+
|
| 253 |
+
doc.add_paragraph()
|
| 254 |
+
|
| 255 |
+
doc.add_heading("Why This Architecture?", level=2)
|
| 256 |
+
|
| 257 |
+
reasons = [
|
| 258 |
+
"CNN: Efficiently extracts visual features from handwritten strokes",
|
| 259 |
+
"BiLSTM: Captures context from both directions (important for language)",
|
| 260 |
+
"CTC Loss: Eliminates need for expensive character-level annotations",
|
| 261 |
+
"Proven: This architecture is the industry standard for OCR tasks"
|
| 262 |
+
]
|
| 263 |
+
for r in reasons:
|
| 264 |
+
doc.add_paragraph(r, style='List Bullet')
|
| 265 |
+
|
| 266 |
+
doc.add_page_break()
|
| 267 |
+
|
| 268 |
+
# ============== DATASET ANALYSIS ==============
|
| 269 |
+
doc.add_heading("5. Dataset Analysis", level=1)
|
| 270 |
+
|
| 271 |
+
doc.add_heading("IAM Handwriting Database", level=2)
|
| 272 |
+
doc.add_paragraph("The model is trained on the IAM Handwriting Database, a widely-used benchmark for handwriting recognition research.")
|
| 273 |
+
|
| 274 |
+
dataset_table = doc.add_table(rows=1, cols=2)
|
| 275 |
+
dataset_table.style = 'Table Grid'
|
| 276 |
+
hdr = dataset_table.rows[0].cells
|
| 277 |
+
hdr[0].text = 'Statistic'
|
| 278 |
+
hdr[1].text = 'Value'
|
| 279 |
+
for cell in hdr:
|
| 280 |
+
cell.paragraphs[0].runs[0].bold = True
|
| 281 |
+
|
| 282 |
+
stats = [
|
| 283 |
+
("Total Samples", "10,373"),
|
| 284 |
+
("Training Set", "6,482 samples"),
|
| 285 |
+
("Validation Set", "976 samples"),
|
| 286 |
+
("Test Set", "2,915 samples"),
|
| 287 |
+
("Unique Characters", "74 (a-z, A-Z, 0-9, space, punctuation)"),
|
| 288 |
+
("Average Text Length", "48-60 characters"),
|
| 289 |
+
("Text Length Range", "5-150 characters"),
|
| 290 |
+
("Source", "University of Bern / Teklia (Hugging Face)")
|
| 291 |
+
]
|
| 292 |
+
|
| 293 |
+
for stat, val in stats:
|
| 294 |
+
row = dataset_table.add_row().cells
|
| 295 |
+
row[0].text = stat
|
| 296 |
+
row[1].text = val
|
| 297 |
+
|
| 298 |
+
doc.add_paragraph()
|
| 299 |
+
|
| 300 |
+
doc.add_heading("Character Distribution", level=2)
|
| 301 |
+
doc.add_paragraph("The dataset follows natural English text frequency distribution:")
|
| 302 |
+
|
| 303 |
+
char_freq = [
|
| 304 |
+
("Space", "Most common (word separator)"),
|
| 305 |
+
("'e'", "13.2% - Most frequent letter"),
|
| 306 |
+
("'t'", "9.4%"),
|
| 307 |
+
("'a'", "8.1%"),
|
| 308 |
+
("'o'", "7.9%"),
|
| 309 |
+
("'i'", "7.0%")
|
| 310 |
+
]
|
| 311 |
+
|
| 312 |
+
for char, freq in char_freq:
|
| 313 |
+
doc.add_paragraph(f"{char}: {freq}", style='List Bullet')
|
| 314 |
+
|
| 315 |
+
doc.add_page_break()
|
| 316 |
+
|
| 317 |
+
# ============== TRAINING RESULTS ==============
|
| 318 |
+
doc.add_heading("6. Training Results", level=1)
|
| 319 |
+
|
| 320 |
+
doc.add_heading("Training Configuration", level=2)
|
| 321 |
+
|
| 322 |
+
config_table = doc.add_table(rows=1, cols=3)
|
| 323 |
+
config_table.style = 'Table Grid'
|
| 324 |
+
hdr = config_table.rows[0].cells
|
| 325 |
+
hdr[0].text = 'Parameter'
|
| 326 |
+
hdr[1].text = 'Value'
|
| 327 |
+
hdr[2].text = 'Rationale'
|
| 328 |
+
for cell in hdr:
|
| 329 |
+
cell.paragraphs[0].runs[0].bold = True
|
| 330 |
+
|
| 331 |
+
config = [
|
| 332 |
+
("Epochs", "10", "Convergence achieved"),
|
| 333 |
+
("Batch Size", "8", "GPU memory optimization"),
|
| 334 |
+
("Learning Rate", "0.001", "Adam default"),
|
| 335 |
+
("Optimizer", "Adam", "Adaptive learning rates"),
|
| 336 |
+
("LR Scheduler", "ReduceLROnPlateau", "Dynamic adjustment"),
|
| 337 |
+
("Gradient Clipping", "5.0", "Stable RNN training"),
|
| 338 |
+
("Image Height", "128px", "Balance detail vs. speed")
|
| 339 |
+
]
|
| 340 |
+
|
| 341 |
+
for param, val, rationale in config:
|
| 342 |
+
row = config_table.add_row().cells
|
| 343 |
+
row[0].text = param
|
| 344 |
+
row[1].text = val
|
| 345 |
+
row[2].text = rationale
|
| 346 |
+
|
| 347 |
+
doc.add_paragraph()
|
| 348 |
+
|
| 349 |
+
doc.add_heading("Training Progress", level=2)
|
| 350 |
+
|
| 351 |
+
progress_table = doc.add_table(rows=1, cols=5)
|
| 352 |
+
progress_table.style = 'Table Grid'
|
| 353 |
+
hdr = progress_table.rows[0].cells
|
| 354 |
+
headers = ['Epoch', 'Train Loss', 'Val Loss', 'CER', 'WER']
|
| 355 |
+
for i, h in enumerate(headers):
|
| 356 |
+
hdr[i].text = h
|
| 357 |
+
hdr[i].paragraphs[0].runs[0].bold = True
|
| 358 |
+
|
| 359 |
+
progress = [
|
| 360 |
+
("1", "3.21", "2.67", "100%", "100%"),
|
| 361 |
+
("2", "1.69", "1.03", "29.3%", "71.8%"),
|
| 362 |
+
("5", "0.60", "0.57", "17.7%", "53.1%"),
|
| 363 |
+
("7", "0.49", "0.46", "14.4%", "46.5%"),
|
| 364 |
+
("10 (Final)", "0.39", "0.38", "12.95%", "42.47%")
|
| 365 |
+
]
|
| 366 |
+
|
| 367 |
+
for epoch, train, val, cer, wer in progress:
|
| 368 |
+
row = progress_table.add_row().cells
|
| 369 |
+
row[0].text = epoch
|
| 370 |
+
row[1].text = train
|
| 371 |
+
row[2].text = val
|
| 372 |
+
row[3].text = cer
|
| 373 |
+
row[4].text = wer
|
| 374 |
+
|
| 375 |
+
doc.add_paragraph()
|
| 376 |
+
doc.add_paragraph("Training Time: ~20 minutes on NVIDIA T4 GPU (1.7-2.1 min/epoch)")
|
| 377 |
+
|
| 378 |
+
doc.add_page_break()
|
| 379 |
+
|
| 380 |
+
# ============== PERFORMANCE METRICS ==============
|
| 381 |
+
doc.add_heading("7. Performance Metrics", level=1)
|
| 382 |
+
|
| 383 |
+
doc.add_heading("Accuracy Metrics", level=2)
|
| 384 |
+
|
| 385 |
+
doc.add_paragraph("""
|
| 386 |
+
Character Error Rate (CER): 12.95%
|
| 387 |
+
- Measures character-level accuracy
|
| 388 |
+
- 87.05% of characters are correctly recognized
|
| 389 |
+
- Industry competitive for handwriting OCR
|
| 390 |
+
|
| 391 |
+
Word Error Rate (WER): 42.47%
|
| 392 |
+
- Measures word-level accuracy
|
| 393 |
+
- 57.53% of words are exactly correct
|
| 394 |
+
- Higher than CER because one character error fails the whole word
|
| 395 |
+
""")
|
| 396 |
+
|
| 397 |
+
doc.add_heading("Understanding CER vs WER", level=2)
|
| 398 |
+
doc.add_paragraph("""Example:
|
| 399 |
+
Ground Truth: "magnificent"
|
| 400 |
+
Prediction: "magnifcent" (missing 'i')
|
| 401 |
+
|
| 402 |
+
CER: 1 error / 11 characters = 9.1%
|
| 403 |
+
WER: 1 error / 1 word = 100%
|
| 404 |
+
|
| 405 |
+
This explains why WER is significantly higher than CER.""")
|
| 406 |
+
|
| 407 |
+
doc.add_heading("Inference Speed", level=2)
|
| 408 |
+
|
| 409 |
+
speed_table = doc.add_table(rows=1, cols=3)
|
| 410 |
+
speed_table.style = 'Table Grid'
|
| 411 |
+
hdr = speed_table.rows[0].cells
|
| 412 |
+
hdr[0].text = 'Hardware'
|
| 413 |
+
hdr[1].text = 'Speed'
|
| 414 |
+
hdr[2].text = 'Memory'
|
| 415 |
+
for cell in hdr:
|
| 416 |
+
cell.paragraphs[0].runs[0].bold = True
|
| 417 |
+
|
| 418 |
+
speeds = [
|
| 419 |
+
("CPU (Intel i7)", "200-500ms/image", "500MB"),
|
| 420 |
+
("GPU (T4)", "50-100ms/image", "2GB"),
|
| 421 |
+
("GPU (V100)", "20-40ms/image", "4GB"),
|
| 422 |
+
("GPU (A100)", "10-20ms/image", "4-8GB")
|
| 423 |
+
]
|
| 424 |
+
|
| 425 |
+
for hw, speed, mem in speeds:
|
| 426 |
+
row = speed_table.add_row().cells
|
| 427 |
+
row[0].text = hw
|
| 428 |
+
row[1].text = speed
|
| 429 |
+
row[2].text = mem
|
| 430 |
+
|
| 431 |
+
doc.add_page_break()
|
| 432 |
+
|
| 433 |
+
# ============== QUICK START GUIDE ==============
|
| 434 |
+
doc.add_heading("8. Quick Start Guide", level=1)
|
| 435 |
+
|
| 436 |
+
doc.add_heading("Installation", level=2)
|
| 437 |
+
doc.add_paragraph("pip install torch datasets pillow numpy huggingface_hub", style='Quote')
|
| 438 |
+
|
| 439 |
+
doc.add_heading("Download Pre-trained Model", level=2)
|
| 440 |
+
code1 = """from huggingface_hub import hf_hub_download
|
| 441 |
+
|
| 442 |
+
model_path = hf_hub_download(
|
| 443 |
+
repo_id="IsmatS/handwriting-recognition-iam",
|
| 444 |
+
filename="best_model.pth"
|
| 445 |
+
)"""
|
| 446 |
+
doc.add_paragraph(code1, style='Quote')
|
| 447 |
+
|
| 448 |
+
doc.add_heading("Load and Use Model", level=2)
|
| 449 |
+
code2 = """import torch
|
| 450 |
+
from PIL import Image
|
| 451 |
+
|
| 452 |
+
# Load checkpoint
|
| 453 |
+
checkpoint = torch.load(model_path, map_location='cpu')
|
| 454 |
+
|
| 455 |
+
# Initialize model (CRNN class from train_colab.ipynb)
|
| 456 |
+
model = CRNN(num_classes=75)
|
| 457 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 458 |
+
model.eval()
|
| 459 |
+
|
| 460 |
+
# Preprocess image
|
| 461 |
+
img = Image.open('handwriting.png').convert('L')
|
| 462 |
+
# Resize maintaining aspect ratio to height=128
|
| 463 |
+
w, h = img.size
|
| 464 |
+
new_w = int(128 * (w / h))
|
| 465 |
+
img = img.resize((new_w, 128), Image.LANCZOS)
|
| 466 |
+
|
| 467 |
+
# Convert to tensor and normalize
|
| 468 |
+
import numpy as np
|
| 469 |
+
img_array = np.array(img) / 255.0
|
| 470 |
+
img_array = (img_array - 0.5) / 0.5
|
| 471 |
+
tensor = torch.FloatTensor(img_array).unsqueeze(0).unsqueeze(0)
|
| 472 |
+
|
| 473 |
+
# Predict
|
| 474 |
+
with torch.no_grad():
|
| 475 |
+
output = model(tensor)
|
| 476 |
+
# Use CTC decoding to get text
|
| 477 |
+
predicted_text = decode_predictions(output, char_mapper)
|
| 478 |
+
print(predicted_text)"""
|
| 479 |
+
doc.add_paragraph(code2, style='Quote')
|
| 480 |
+
|
| 481 |
+
doc.add_page_break()
|
| 482 |
+
|
| 483 |
+
# ============== USE CASES ==============
|
| 484 |
+
doc.add_heading("9. Use Cases & Applications", level=1)
|
| 485 |
+
|
| 486 |
+
use_cases = [
|
| 487 |
+
("Document Digitization", "Convert handwritten notes, letters, and historical documents to searchable digital text"),
|
| 488 |
+
("Healthcare", "Transcribe handwritten prescriptions and medical notes"),
|
| 489 |
+
("Education", "Grade handwritten assignments and exams automatically"),
|
| 490 |
+
("Banking & Finance", "Process handwritten checks and forms"),
|
| 491 |
+
("Postal Services", "Read handwritten addresses on mail"),
|
| 492 |
+
("Legal", "Digitize handwritten contracts and legal documents"),
|
| 493 |
+
("Archive Management", "Make historical handwritten records searchable"),
|
| 494 |
+
("Personal Productivity", "Convert handwritten to-do lists and notes to digital format")
|
| 495 |
+
]
|
| 496 |
+
|
| 497 |
+
for title, desc in use_cases:
|
| 498 |
+
p = doc.add_paragraph()
|
| 499 |
+
run = p.add_run(title + ": ")
|
| 500 |
+
run.bold = True
|
| 501 |
+
p.add_run(desc)
|
| 502 |
+
|
| 503 |
+
doc.add_page_break()
|
| 504 |
+
|
| 505 |
+
# ============== FUTURE IMPROVEMENTS ==============
|
| 506 |
+
doc.add_heading("10. Future Improvements", level=1)
|
| 507 |
+
|
| 508 |
+
improvements = [
|
| 509 |
+
("Attention Mechanism", "Add attention layers for better focus on relevant image regions"),
|
| 510 |
+
("Transformer Architecture", "Implement Vision Transformer (ViT) for potentially better accuracy"),
|
| 511 |
+
("Data Augmentation", "Add rotation, elastic distortion, and noise for robustness"),
|
| 512 |
+
("Model Scaling", "Increase to 20-50M parameters for improved accuracy"),
|
| 513 |
+
("Multi-line Support", "Extend to paragraph and document-level recognition"),
|
| 514 |
+
("Language Model Integration", "Add spell-checking and context-aware corrections"),
|
| 515 |
+
("Multilingual Support", "Extend character set to support multiple languages"),
|
| 516 |
+
("Real-time Processing", "Optimize for video stream processing"),
|
| 517 |
+
("Mobile Deployment", "Create TensorFlow Lite / ONNX models for mobile devices")
|
| 518 |
+
]
|
| 519 |
+
|
| 520 |
+
for title, desc in improvements:
|
| 521 |
+
p = doc.add_paragraph()
|
| 522 |
+
run = p.add_run(title + ": ")
|
| 523 |
+
run.bold = True
|
| 524 |
+
p.add_run(desc)
|
| 525 |
+
|
| 526 |
+
doc.add_page_break()
|
| 527 |
+
|
| 528 |
+
# ============== CONCLUSION ==============
|
| 529 |
+
doc.add_heading("11. Conclusion", level=1)
|
| 530 |
+
|
| 531 |
+
conclusion = """This handwriting recognition project successfully demonstrates the implementation of a production-ready OCR system using modern deep learning techniques.
|
| 532 |
+
|
| 533 |
+
Key Accomplishments:
|
| 534 |
+
"""
|
| 535 |
+
doc.add_paragraph(conclusion)
|
| 536 |
+
|
| 537 |
+
accomplishments = [
|
| 538 |
+
"Achieved 87% character-level accuracy on the IAM benchmark dataset",
|
| 539 |
+
"Implemented industry-standard CNN-BiLSTM-CTC architecture",
|
| 540 |
+
"Trained efficiently in ~20 minutes on consumer GPU hardware",
|
| 541 |
+
"Created comprehensive documentation and visualization",
|
| 542 |
+
"Deployed pre-trained model on Hugging Face Hub for easy access",
|
| 543 |
+
"Provided complete training pipeline in Google Colab-ready notebook"
|
| 544 |
+
]
|
| 545 |
+
|
| 546 |
+
for acc in accomplishments:
|
| 547 |
+
doc.add_paragraph(acc, style='List Bullet')
|
| 548 |
+
|
| 549 |
+
doc.add_paragraph()
|
| 550 |
+
doc.add_paragraph("The project serves as both a practical tool for handwriting recognition and an educational resource for understanding deep learning-based OCR systems.")
|
| 551 |
+
|
| 552 |
+
doc.add_paragraph()
|
| 553 |
+
|
| 554 |
+
# Final note
|
| 555 |
+
final = doc.add_paragraph()
|
| 556 |
+
final_run = final.add_run("Model available at: ")
|
| 557 |
+
final.add_run("https://huggingface.co/IsmatS/handwriting-recognition-iam")
|
| 558 |
+
|
| 559 |
+
doc.add_paragraph()
|
| 560 |
+
|
| 561 |
+
# References
|
| 562 |
+
doc.add_heading("References", level=2)
|
| 563 |
+
refs = [
|
| 564 |
+
"IAM Handwriting Database - University of Bern",
|
| 565 |
+
"PyTorch Documentation - pytorch.org",
|
| 566 |
+
"CTC Loss Paper - Graves et al., 2006",
|
| 567 |
+
"CRNN Architecture - Shi et al., 2015"
|
| 568 |
+
]
|
| 569 |
+
for ref in refs:
|
| 570 |
+
doc.add_paragraph(ref, style='List Bullet')
|
| 571 |
+
|
| 572 |
+
# Save document
|
| 573 |
+
output_path = '/home/user/handwriting_recognition/Handwriting_Recognition_Presentation.docx'
|
| 574 |
+
doc.save(output_path)
|
| 575 |
+
print(f"Presentation saved to: {output_path}")
|
| 576 |
+
return output_path
|
| 577 |
+
|
| 578 |
+
if __name__ == "__main__":
|
| 579 |
+
create_presentation()
|