|
|
--- |
|
|
language: |
|
|
- fa |
|
|
base_model: |
|
|
- google/mobilenet_v2_1.0_224 |
|
|
pipeline_tag: image-classification |
|
|
--- |
|
|
%%writefile README.md |
|
|
# PersianDigitOCR |
|
|
|
|
|
## Overview |
|
|
PersianDigitOCR is a deep learning model designed for recognizing handwritten Persian (Farsi) digits (۰-۹) from images. Built by fine-tuning the MobileNetV2 architecture pre-trained on ImageNet, this model achieves a validation accuracy of 99.75% on a subset of the HODA dataset. It is optimized for 96x96 pixel grayscale images and outputs Persian digit characters using Unicode mappings (U+06F0 to U+06F9). |
|
|
|
|
|
- **Pipeline Tag**: `image-classification` |
|
|
- **Date**: October 08, 2025 |
|
|
|
|
|
## Model Details |
|
|
- **Base Model**: MobileNetV2 (from [google/mobilenet_v2_1.0_224](https://huggingface.co/google/mobilenet_v2_1.0_224)) |
|
|
- **Input**: Grayscale images resized to 96x96 pixels |
|
|
- **Output**: Predicted digit as a Persian Unicode character (e.g., '۰' for 0) |
|
|
- **Training Data**: Subset of 20,000 images from the HODA dataset (80% training, 20% validation) |
|
|
|
|
|
|
|
|
## Usage |
|
|
|
|
|
```python |
|
|
import requests |
|
|
# Step 1: Download the model from Hugging Face |
|
|
model_filename = 'PersianDigitOCR.keras' |
|
|
repo_id = 'shaghxyegh/PersianDigitOCR' |
|
|
file_url = f"https://huggingface.co/{repo_id}/resolve/main/{model_filename}" |
|
|
|
|
|
print(f"Downloading model from {file_url}...") |
|
|
response = requests.get(file_url) |
|
|
if response.status_code == 200: |
|
|
with open(model_filename, 'wb') as f: |
|
|
f.write(response.content) |
|
|
print(f"Model downloaded successfully as '{model_filename}'") |
|
|
else: |
|
|
raise ValueError(f"Failed to download model. Status code: {response.status_code}. Check if the file '{model_filename}' exists in your repo at {file_url}") |
|
|
|
|
|
# Step 2: Load the model |
|
|
model = load_model(model_filename) |
|
|
print("Model loaded successfully!") |
|
|
``` |
|
|
|
|
|
## Performance |
|
|
|
|
|
Validation Accuracy: 99.75% on 4,000 validation images |
|
|
Training Accuracy: 99.69% (Epoch 30) |
|
|
Context: Trained with batch size 32, 30 epochs, Adam optimizer, and data augmentation (rotation, zoom, shift). |