Skip to main content

An pytorch ocr base library for MBBank lib

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mb_capcha_ocr-0.1.4-py3-none-any.whl (44.5 MB view details)

Uploaded Python 3

File details

Details for the file mb_capcha_ocr-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mb_capcha_ocr-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9955d4cf5af54052f4dd9ae6f500bed2f97310656afe037bb367e97547b95013
MD5 27e425a5f89a8a5479986b5a1af381e4
BLAKE2b-256 903b9b47bb10708b4a9cb1099cee701702c0c14a77025a7f751e97c48a2bc60a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page