Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- th
|
| 4 |
+
- en
|
| 5 |
+
metrics:
|
| 6 |
+
- cer
|
| 7 |
+
tags:
|
| 8 |
+
- trocr
|
| 9 |
+
- image-to-text
|
| 10 |
+
pipeline_tag: image-to-text
|
| 11 |
+
library_name: transformers
|
| 12 |
+
license: apache-2.0
|
| 13 |
+
---
|
| 14 |
+
# Thai-TrOCR Model
|
| 15 |
+
|
| 16 |
+
## 🚀 Final Model Available Now!
|
| 17 |
+
**The final version of the Thai-TrOCR model is out!** Check it out here: [huggingface.com/openthaigpt/thai-trocr](https://huggingface.co/openthaigpt/thai-trocr)
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## Introduction
|
| 22 |
+
**Thai-TrOCR** is an advanced Optical Character Recognition (OCR) model fine-tuned specifically for recognizing handwritten text in **Thai** and **English**. Built on the robust TrOCR architecture, this model combines a Vision Transformer encoder with an Electra-based text decoder, allowing it to effectively handle multilingual text-line images.
|
| 23 |
+
|
| 24 |
+
Designed for **efficiency and accuracy**, Thai-TrOCR is lightweight, making it ideal for deployment in resource-constrained environments without compromising on performance.
|
| 25 |
+
|
| 26 |
+
### Key Features:
|
| 27 |
+
- **Encoder**: TrOCR Base Handwritten
|
| 28 |
+
- **Decoder**: Electra Small (Trained with Thai corpus)
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Training Dataset
|
| 33 |
+
Thai-TrOCR was trained using the following datasets:
|
| 34 |
+
- `pythainlp/thai-wiki-dataset-v3`
|
| 35 |
+
- `pythainlp/thaigov-corpus`
|
| 36 |
+
- `Salesforce/wikitext`
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## How to Use This Beta Model
|
| 41 |
+
Here’s a quick guide to get started with the Thai-TrOCR model in **PyTorch**:
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
| 45 |
+
from PIL import Image
|
| 46 |
+
import requests
|
| 47 |
+
|
| 48 |
+
# Load processor and model
|
| 49 |
+
processor = TrOCRProcessor.from_pretrained('suchut/thaitrocr-base-handwritten-beta2')
|
| 50 |
+
model = VisionEncoderDecoderModel.from_pretrained('suchut/thaitrocr-base-handwritten-beta2')
|
| 51 |
+
|
| 52 |
+
# Load an image
|
| 53 |
+
url = 'your_image_url_here'
|
| 54 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 55 |
+
|
| 56 |
+
# Process and generate text
|
| 57 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
| 58 |
+
generated_ids = model.generate(pixel_values)
|
| 59 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 60 |
+
print(generated_text)
|
| 61 |
+
```
|