File size: 675 Bytes
daabd1d
 
 
4d8a965
daabd1d
 
 
 
 
 
 
 
 
 
 
 
 
 
4d8a965
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
---
license: mit
---
```python
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
import requests

# load image from the IAM database
url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg'
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")

processor = TrOCRProcessor.from_pretrained('kun826/trocr_handwrite_option4')
model = VisionEncoderDecoderModel.from_pretrained('kun826/trocr_handwrite_option4')
pixel_values = processor(images=image, return_tensors="pt").pixel_values

generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
```