Skip to main content

OCR Model Training and Prediction

This project is designed to train and use an Optical Character Recognition (OCR) model for recognizing characters in CAPTCHA images.

Project Structure

  • mb_capcha_ocr/: Contains the core OCR model and prediction logic.
  • train_model/: Contains the training script for the OCR model.

Installation and Setup for Training

  1. Clone the repository:

    git clone https://github.com/thedtvn/mbbank-capcha-ocr
    cd mbbank-capcha-ocr
    cd train_model
    
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`
    
  3. Install the required dependencies:

    pip install -r train_requirements.txt
    

Training the Model

  1. Place your training and testing images in the dataset/ directory. The images should be named in the format {label}.(png|jpg|jpeg).

  2. Run the training script:

    python train.py
    
  3. The trained model will be saved as model.onnx in the directory.

Using the Model for Prediction

from PIL import Image
from mb_capcha_ocr import OcrModel

model = OcrModel()  # model_path optional if using custom model
img = Image.open("path_to_image.png")
predicted_text = model.predict(img)
print(predicted_text)

Files

  • train_model/train.py: Script to train the OCR model.
  • mb_capcha_ocr/predict.py: Script to predict text from an image using the trained OCR model.
  • requirements.txt: List of dependencies required for the project.

Dependencies

  • Python 3.x
  • numpy
  • onnxruntime
  • Pillow

Dependencies Training

  • Python 3.x
  • torch
  • torchvision
  • matplotlib
  • Pillow
  • onnx

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Credits

Best thanks to CookieGMVN for providing the dataset V1 V2.

Metadata

Release files for mb-capcha-ocr 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mb-capcha-ocr 0.1.6
File Interpreter ABI Platform
mb_capcha_ocr-0.1.6-py3-none-any.whl Python 3 none any Details

Release files / mb_capcha_ocr-0.1.6-py3-none-any.whl

Download URL mb_capcha_ocr-0.1.6-py3-none-any.whl
Size 44.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c1a9c7d1c59808f94d5f0fc5f473b1593667a26206c8f4d005efe80d692356c9
BLAKE2b-256 checksum
How to use checksums
47dcbe895a61ab3a4397fae78dafed3fc5d069addad293f980a080aca3be6960
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.1.6 This release

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page