Downloads · 30 days
164
2% of all-time downloads
chinmays18/medical-prescription-ocr
medical-prescription-ocr is a machine learning model from chinmays18. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This model is a fine-tuned version of naver-clova-ix/donut-base specifically trained to recognize handwritten medical prescriptions. It combines state-of-the-art OCR capabilities with domain-specific training to accur…
Downloads · 30 days
164
2% of all-time downloads
All-time downloads
7.3K
Public
Parameters
202M
810 MB on disk
Likes
8
Public
Click a slice to open those files.
.safetensors809 MB · 99%
How the weights are stored.
F32202M · 100%
From the Hugging Face model README
This model is a fine-tuned version of naver-clova-ix/donut-base specifically trained to recognize handwritten medical prescriptions. It combines state-of-the-art OCR capabilities with domain-specific training to accurately extract text from doctor's handwritten notes.
This model is designed for:
Important: This model is NOT validated for clinical use and should not be used for actual medical diagnosis or prescription verification.
The model was trained using a gradual augmentation approach:
This strategy helps the model learn clean patterns first, then adapt to more challenging variations.
from transformers import DonutProcessor, VisionEncoderDecoderModel
from PIL import Image
import torch
# Load the model and processor
processor = DonutProcessor.from_pretrained("chinmays18/medical-prescription-ocr")
model = VisionEncoderDecoderModel.from_pretrained("chinmays18/medical-prescription-ocr")
# Move to GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
# Process an image
image = Image.open("prescription.jpg").convert("RGB")
pixel_values = processor(images=image, return_tensors="pt").pixel_values.to(device)
# Generate text
task_prompt = "<s_ocr>"
decoder_input_ids = processor.tokenizer(task_prompt, return_tensors="pt").input_ids.to(device)
generated_ids = model.generate(
pixel_values,
decoder_input_ids=decoder_input_ids,
max_length=512,
num_beams=1,
early_stopping=True
)
# Decode the generated text
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text)
If you use this model in your research, please cite:
@misc{shrivastava2024medicalocr,
author = {Chinmay Shrivastava},
title = {Medical Prescription OCR},
year = {2024},
publisher = {Hugging Face},
journal = {Hugging Face Model Hub},
url = {https://huggingface.co/chinmays18/medical-prescription-ocr}
}
Base architecture: NAVER Clova AI's Donut team Training framework: PyTorch Lightning Dataset inspiration: IAM Handwriting Database
Make sure to also update the datasets field from custom-iam-medical to chinmays18/medical-prescription-dataset to properly link to your dataset.