dsupa's picture
Update README.md
abe62d8
metadata
tags:
  - trocr
  - image-to-text
widget:
  - src: >-
      https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test1.JPG
    example_title: test 1
  - src: >-
      https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test2.JPG
    example_title: test 2
  - src: >-
      https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test3.JPG
    example_title: test 3
  - src: >-
      https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test4.JPG
    example_title: test 4
  - src: >-
      https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test5.JPG
    example_title: test 5
  - src: >-
      https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test6.JPG
    example_title: test 6

How to use

Here is how to use this model in PyTorch:

from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image

processor = TrOCRProcessor.from_pretrained('dsupa/mangaocr-hoogberta-v2')
model = VisionEncoderDecoderModel.from_pretrained('dsupa/mangaocr-hoogberta-v2')

def predict(image_path):
    image = Image.open(image_path).convert("RGB")
    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]

    return generated_text

image_path = "your_img.jpg"
pred = predit(image_path)
print(pred)