File size: 9,512 Bytes
3d263fa fba3a76 3d263fa 7111e1a 58c89ae 7111e1a 58c89ae 7111e1a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | ---
title: LCR OCR API
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
app_file: app.py
pinned: false
---
# Local Civil Registry Document Digitization and Data Extraction
## Using CRNN+CTC, Multinomial Naive Bayes, and Named Entity Recognition
**Thesis Project by:**
- Shane Mark C. Blanco
- Princess A. Pasamonte
- Irish Faith G. Ramirez
**Institution:** Tarlac State University, College of Computer Studies
---
## π Project Overview
This system automates the digitization and data extraction of Philippine Civil Registry documents using advanced machine learning algorithms:
### Target Documents:
- **Form 1A** - Birth Certificate
- **Form 2A** - Death Certificate
- **Form 3A** - Marriage Certificate
- **Form 90** - Application of Marriage License
### Key Features:
β
OCR for printed and handwritten text
β
Automatic document classification
β
Named entity extraction (names, dates, places)
β
Auto-fill digital forms
β
MySQL database storage
β
Searchable digital archive
β
Data visualization dashboard
---
## ποΈ System Architecture
```
Input: Scanned Civil Registry Form
β
1. Image Preprocessing
β
2. CRNN+CTC β Text Recognition
β
3. Multinomial Naive Bayes β Document Classification
β
4. spaCy NER β Entity Extraction
β
5. Data Validation & Storage β MySQL Database
β
Output: Digitized & Searchable Record
```
---
## π Quick Start
### Prerequisites
- Python 3.8+
- CUDA-capable GPU (recommended) or CPU
- 8GB RAM minimum
### Installation
```bash
# 1. Clone or download the project
cd civil_registry_ocr
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Download spaCy model
python -m spacy download en_core_web_sm
```
### Quick Test
```python
from inference import CivilRegistryOCR
# Load model
ocr = CivilRegistryOCR('checkpoints/best_model.pth')
# Recognize text
text = ocr.predict('test_images/sample_name.jpg')
print(f"Recognized: {text}")
```
---
## π Project Files
### Core Implementation Files:
1. **crnn_model.py** - CRNN+CTC neural network architecture
2. **dataset.py** - Data loading and preprocessing
3. **train.py** - Model training script
4. **inference.py** - Prediction and inference
5. **utils.py** - Helper functions and metrics
6. **requirements.txt** - Python dependencies
7. **IMPLEMENTATION_GUIDE.md** - Detailed implementation guide
### Additional Components (To be created):
8. **document_classifier.py** - Multinomial Naive Bayes classifier
9. **ner_extractor.py** - Named Entity Recognition
10. **web_app.py** - Web application (Flask/FastAPI)
11. **database.py** - MySQL integration
---
## π Training the Model
### 1. Prepare Your Data
Organize images and labels:
```
data/
train/
form1a/
name_001.jpg
name_001.txt
form2a/
...
val/
...
```
### 2. Create Annotations
```python
from dataset import create_annotation_file
create_annotation_file('data/train', 'data/train_annotations.json')
create_annotation_file('data/val', 'data/val_annotations.json')
```
### 3. Train Model
```bash
python train.py
```
Monitor metrics:
- Character Error Rate (CER)
- Word Error Rate (WER)
- Training/Validation Loss
### 4. Evaluate
```python
from utils import calculate_cer, calculate_wer
predictions = [ocr.predict(img) for img in test_images]
cer = calculate_cer(predictions, ground_truths)
print(f"CER: {cer:.2f}%")
```
---
## π Web Application
### Start the Server
```bash
python web_app.py
```
### API Endpoints
**POST /api/ocr** - Process document
```bash
curl -X POST -F "file=@birth_cert.jpg" http://localhost:8000/api/ocr
```
**Response:**
```json
{
"text": "Juan Dela Cruz\n01/15/1990\nTarlac City",
"form_type": "form1a",
"entities": {
"persons": ["Juan Dela Cruz"],
"dates": ["01/15/1990"],
"locations": ["Tarlac City"]
}
}
```
---
## π― Expected Performance
Based on thesis objectives:
### CRNN+CTC Model:
- **Target CER:** < 5%
- **Target Accuracy:** > 95%
- Handles both printed and handwritten text
### Document Classifier (MNB):
- **Target Accuracy:** > 90%
- Fast classification (< 100ms)
### NER (spaCy):
- **F1 Score:** > 85%
- Extracts: Names, Dates, Places
---
## π§ͺ Testing
### ISO 25010 Evaluation
**Usability Testing:**
```python
# Metrics to measure:
- Task completion rate
- Average time per task
- User satisfaction score (SUS)
```
**Reliability Testing:**
```python
# Metrics to measure:
- System uptime %
- Error rate
- Recovery time
```
### Confusion Matrix
```python
from sklearn.metrics import confusion_matrix
import seaborn as sns
cm = confusion_matrix(true_labels, predicted_labels)
sns.heatmap(cm, annot=True)
```
---
## πΎ Database Schema
### Birth Certificates Table
```sql
CREATE TABLE birth_certificates (
id INT PRIMARY KEY AUTO_INCREMENT,
child_name VARCHAR(255),
date_of_birth DATE,
place_of_birth VARCHAR(255),
sex CHAR(1),
father_name VARCHAR(255),
mother_name VARCHAR(255),
raw_text TEXT,
form_image LONGBLOB,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```
---
## π System Requirements
### Minimum:
- CPU: Intel i5 or equivalent
- RAM: 8GB
- Storage: 10GB
- OS: Windows 10, Ubuntu 18.04, macOS 10.14
### Recommended:
- CPU: Intel i7 or equivalent
- GPU: NVIDIA GTX 1060 or better
- RAM: 16GB
- Storage: 50GB SSD
---
## π Data Privacy & Security
Following Philippine Data Privacy Act (RA 10173):
- β
Encrypted data transmission
- β
Access control and authentication
- β
Audit logging
- β
Regular security updates
- β
Data retention policies
---
## π Key Algorithms
### 1. CRNN+CTC
**Purpose:** Text recognition from images
**Strengths:** Handles variable-length sequences, no character segmentation needed
**Reference:** Shi et al. (2016)
### 2. Multinomial Naive Bayes
**Purpose:** Document classification
**Strengths:** Fast, efficient, works well with text data
**Reference:** McCallum & Nigam (1998)
### 3. Named Entity Recognition
**Purpose:** Extract entities (names, dates, places)
**Strengths:** Pre-trained, accurate, easy to use
**Reference:** spaCy (Honnibal & Montani, 2017)
---
## π οΈ Troubleshooting
### Low Accuracy?
1. Increase training data (target: 10,000+ samples)
2. Use data augmentation
3. Train longer (100+ epochs)
4. Clean your dataset
### Out of Memory?
1. Reduce batch size
2. Use smaller image dimensions
3. Use gradient accumulation
4. Enable mixed precision
### Slow Inference?
1. Use GPU if available
2. Batch process images
3. Optimize model (ONNX)
4. Cache frequent results
---
## π Documentation
- **IMPLEMENTATION_GUIDE.md** - Complete step-by-step guide
- **API_DOCUMENTATION.md** - API reference (to be created)
- **USER_MANUAL.md** - End-user guide (to be created)
---
## π Academic References
### Key Papers:
1. **CRNN**
Shi, B., Bai, X., & Yao, C. (2016). An end-to-end trainable neural network for image-based sequence recognition and its application to scene text recognition. *IEEE TPAMI*.
2. **CTC Loss**
Graves, A., et al. (2006). Connectionist temporal classification: Labelling unsegmented sequence data with recurrent neural networks. *ICML*.
3. **Naive Bayes**
McCallum, A., & Nigam, K. (1998). A comparison of event models for naive bayes text classification. *AAAI Workshop*.
4. **spaCy**
Honnibal, M., & Montani, I. (2017). spaCy 2: Natural language understanding with Bloom embeddings, convolutional neural networks and incremental parsing.
---
## π₯ Contributors
**Researchers:**
- Shane Mark C. Blanco
- Princess A. Pasamonte
- Irish Faith G. Ramirez
**Advisers:**
- Mr. Rengel V. Corpuz (Technical Adviser)
- Mr. Joselito T. Tan (Subject Teacher)
**Institution:**
Tarlac State University
College of Computer Studies
Bachelor of Science in Computer Science
---
## π Support
For questions regarding this implementation:
1. Review IMPLEMENTATION_GUIDE.md
2. Check code documentation
3. Consult with thesis advisers
---
## π License
This project is for academic purposes as part of a thesis requirement.
---
## β
Implementation Checklist
### Phase 1: Setup β
- [x] Install dependencies
- [x] Set up project structure
- [x] Prepare development environment
### Phase 2: Data Preparation
- [ ] Collect civil registry form images
- [ ] Create annotations
- [ ] Split into train/val/test sets
### Phase 3: Model Development
- [ ] Train CRNN+CTC model
- [ ] Train document classifier
- [ ] Integrate NER system
### Phase 4: Web Application
- [ ] Develop Flask/FastAPI backend
- [ ] Create frontend interface
- [ ] Implement database integration
### Phase 5: Testing
- [ ] Accuracy testing
- [ ] Black-box testing
- [ ] ISO 25010 evaluation
- [ ] User acceptance testing
### Phase 6: Deployment
- [ ] Optimize for production
- [ ] Set up server
- [ ] Deploy application
- [ ] Monitor performance
---
## π― Success Metrics
Target metrics for thesis evaluation:
| Metric | Target | Status |
|--------|--------|--------|
| OCR Accuracy | > 95% | Pending |
| CER | < 5% | Pending |
| Classifier Accuracy | > 90% | Pending |
| NER F1 Score | > 85% | Pending |
| Response Time | < 2s | Pending |
| System Uptime | > 99% | Pending |
---
**Good luck with your thesis defense! πβ¨**
For detailed implementation instructions, see **IMPLEMENTATION_GUIDE.md**
|