Downloads · 30 days
6
0% of all-time downloads
vanshp123/ocrmnist
ocrmnist is a image-to-text model from vanshp123. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as apache-2.0.
This repository demonstrates how to perform Optical Character Recognition (OCR) using the Hugging Face Transformers library. The code in this repository utilizes a pretrained model for OCR on images.
Downloads · 30 days
6
0% of all-time downloads
All-time downloads
1.8K
Public
Repo size
3.1 GB
Likes
0
Public
Click a slice to open those files.
.bin1.5 GB · 100%
From the Hugging Face model README
# OCR with Hugging Face Transformers
This repository demonstrates how to perform Optical Character Recognition (OCR) using the Hugging Face Transformers library. The code in this repository utilizes a pretrained model for OCR on images.
Before you can run the code, you'll need to install the required libraries. You can do this with pip:
pip install transformers
pip install pillow
You can use the provided code to perform OCR on images. Here are the basic steps:
from transformers import VisionEncoderDecoderModel
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
import requests
model = VisionEncoderDecoderModel.from_pretrained("vanshp123/ocrmnist")
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-stage1')
"/content/left_digit_section_4.png" with the path to your image:image = Image.open("/content/left_digit_section_4.png").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]
generated_text will contain the text recognized from the image.You can use this code as a starting point for your OCR projects. It's important to adapt it to your specific use case and customize it as needed.
This code uses models from the Hugging Face Transformers library, and you should review their licensing and usage terms for the pretrained models.