CoolFace
Modelpublic

0cve0/OpenMLKitOCR

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
2likes178downloads
Model Card

๐Ÿ›๏ธ OpenMLkit OCR Models

This repository hosts a collection of highly optimized, lightweight, on-device OCR (Optical Character Recognition) models extracted from Google ML Kit APK components. These models are designed to run fully offline and are fully compatible with OpenMLkitOCR, a lightweight offline OCR engine for Python.

The repository includes:

  • โ€”Text Detection Model: A Region Proposal Network (RPN) architecture (rpn_detector.tflite) that identifies text bounding boxes in image tiles.
  • โ€”Text Recognition Models: Lightweight CRNN + CTC model pipelines for 15+ different languages and scripts.

๐Ÿ›๏ธ Supported Languages and Scripts

Below is the registry of the available models, vocabulary maps, and language model priors stored in this repository:

CodeScript / LanguageRecognizer ModelLabel Map FileLanguage Model / Priors
detectorText Detection (All)rpn_detector.tfliteโ€”โ€”
enLatin / Englishline_recognizer.fbLabelMap.pbโ€”
ruCyrillic / Russianrecognizer_cyrl.tfliteLabelMap_cyrl.pbFST LM + Priors
zhChinese / Han (Hani)recognizer_hani.tfliterecognizer_hani_label_map.pbFST LM + Priors
jaJapanese (Jpan)recognizer_jpan.tfliterecognizer_jpan_label_map.pbFST LM + Priors
koKorean (Kore)recognizer_kore.tfliterecognizer_kore_label_map.pbFST LM + Priors
arArabic (Arab)recognizer_arab_retrained.tfliterecognizer_arab_label_map.pbFST LM + Priors
heHebrew (Hebr)hebr.tflitehebr_label_map.pbPriors
kaGeorgian (Geor)geor.tflitegeor_label_map.pbPriors
bnBengali & Devanagari (Bede)bede.tflitebede_label_map.pbPriors
guGujarati (Gujr)gocr_tflite_recognizer_gujr.tflitegocr_tflite_recognizer_gujr_label_map.pbPriors
knKannada (Knda)recognizer_knda.tfliterecognizer_knda_label_map.pbFST LM + Priors
mlMalayalam (Mlym)recognizer_mlym.tfliterecognizer_mlym_label_map.pbFST LM + Priors
taTamil (Taml)recognizer_taml.tfliterecognizer_taml_label_map.pbFST LM + Priors
teTelugu (Telu)recognizer_telu.tfliterecognizer_telu_label_map.pbFST LM + Priors
viVietnamese / Latingocr_tflite_recognizer_latn_vi.tflitegocr_tflite_recognizer_latn_vi_label_map.pbPriors

๐Ÿ“‚ File Types Explained

  1. 1.*`.tflite / .fb` (Neural Network weights)*:
  2. 2.detector/rpn_detector.tflite is a Convolutional Neural Network (CNN) that processes 256x256 tiles of the image and predicts text bounding boxes.
  3. 3.recognizer_*.tflite and line_recognizer.fb are CRNN (Convolutional Recurrent Neural Network) architectures that predict CTC logits for cropped text line images.
  4. 4.*`labelmap.pb / LabelMap.pb` (Vocabulary)**:
  5. 5.Binary Protobuf files mapping character indices to Unicode symbols for decoding CTC outputs.
  6. 6.*`lm.compactfst.gz & .syms` (Language Models)*:
  7. 7.Compact Finite State Transducer (FST) language models and symbol mapping files. These are used for advanced Beam Search decoding, correcting spelling and character sequences based on word frequencies.
  8. 8.*`prior.pb` / `*config.pb` (Priors & Config)**:
  9. 9.Character prior probabilities and model configurations used to calibrate neural network outputs before applying the language model.

๐Ÿš€ How to Use with openmlkitOCR

The Python package openmlkitOCR handles automatic downloading and caching of these models from Hugging Face if they are not present locally.

1. Installation

Install the library directly using pip:

bash
pip install openmlkitOCR

2. Python Usage Example

python
import os
import cv2
from openmlkit import OpenMLKitOCR

# Configure the pipeline to pull models from this Hugging Face repository
os.environ["OPENMLKIT_MODEL_REPO"] = "0cve0/OpenMLKitOCR"

# Initialize the pipeline for a specific language (e.g., 'en' for English/Latin)
# This will automatically download and cache the detector and recognizer files.
ocr = OpenMLKitOCR(lang='en')

# Load an image
image = cv2.imread("test_image.jpg")

# Run OCR (detection & recognition)
results = ocr.run(image, score_threshold=0.35)

# Output the localized text bounding boxes and recognised characters
for item in results:
    print(f"Box: {item['box']} -> Text: {item['text']}")

โš–๏ธ License and Disclaimer

  • โ€”Software: The Python library OpenMLkitOCR is licensed under the Apache 2.0 License.
  • โ€”Model Weights: The model weights and configurations in this repository are extracted from Google ML Kit APK components and are subject to Google's terms of service and license agreements. These models are intended for educational, research, and non-commercial local testing purposes.