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)