license-plate-detector / micro_ocr.py
mertbozkurt's picture
Add v1
ffbdc6a
raw
history blame
579 Bytes
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
def plate_rec(img):
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-printed')
model = VisionEncoderDecoderModel.from_pretrained('mertbozkurt/trocr-base-printed_license_plates_ocr')
pixel_values = processor(images=img, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)
#generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return generated_text