File size: 568 Bytes
0e12aee |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
import requests
url = './dataset/val/0003.png'
image = Image.open(url).convert("RGB")
processor = TrOCRProcessor.from_pretrained('./model/checkpoint-80')
model = VisionEncoderDecoderModel.from_pretrained('./model/checkpoint-80').to("cuda")
pixel_values = processor(images=image, return_tensors="pt").pixel_values.to("cuda")
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text)
|