Vietnamese-TrOCR
Collection
Transformer-based Optical Character Recognition with Pre-trained Models for Vietnamese Handwritten
•
2 items
•
Updated
model = VisionEncoderDecoderModel.from_pretrained('AnhxtanhLab/vietnamese-trocr-base-handwritten')
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten")
# Move model to GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
def predict_text(image):
# Process image and move it to the correct device
pixel_values = processor(image, return_tensors="pt").pixel_values
pixel_values = pixel_values.to(device)
# Generate prediction
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return generated_text
Base model
microsoft/trocr-base-handwritten