Run this model with HF Jobs
Run Ali0044/Qalam-Net on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Ali0044/Qalam-Net. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Ali0044/Qalam-Net on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Ali0044/Qalam-Net with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Ali0044/Qalam-Net with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://Ali0044/Qalam-Net") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files5 unmodified lines6789101112131415167 unmodified lines2425262728293031323334353637383940414243444546474849505152535455565758592 unmodified lines62636465666768697071727374757677787980818283848586875 unmodified lines- arabic- keras- jax---# Qalam-Net (قلم-نت): Advanced Arabic OCRQalam-Net is a high-performance, cross-backend Optical Character Recognition (OCR) model for Arabic. Built on **Keras 3**, it supports **JAX**, **PyTorch**, and **TensorFlow** backends.## 🚀 Quick Start (Advanced Usage)7 unmodified lines### 2. Implementation```pythonimport osos.environ["KERAS_BACKEND"] = "jax" # Options: "jax", "tensorflow", "torch"import kerasimport numpy as npimport cv2class QalamNet:def __init__(self, repo_id="Ali0044/Qalam-Net"):# Download and load the latest model using the hf:// shorthand# This automatically downloads the model.keras file from the root of the repoself.model = keras.saving.load_model(f"hf://{repo_id}")# Standard Arabic Vocabulary (Matches training set)self.vocab = [' ', '!', '"', '#', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '=', '?', '[', ']', 'ء', 'آ', 'أ', 'ؤ', 'إ', 'ئ', 'ا', 'ب', 'ة', 'ت', 'ث', 'ج', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'س', 'ش', 'ص', 'ض', 'ط', 'ظ', 'ع', 'غ', 'ـ', 'ف', 'ق', 'ك', 'ل', 'م', 'ن', 'ه', 'و', 'ى', 'ي', 'ً', 'ٌ', 'ٍ', 'َ', 'ُ', 'ِ', 'ّ', 'ْ', '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']def preprocess(self, image_path):# 1. Load as grayscaleimg = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)# 2. Resize to 128 (width) x 32 (height)img = cv2.resize(img, (128, 32))# 3. Normalizeimg = (img / 255.0).astype(np.float32)# 4. Transpose (W, H) -> (H, W) for CRNN processingimg = img.T# 5. Expand dimensions for batch and channelimg = np.expand_dims(img, axis=-1)return np.expand_dims(img, axis=0)def predict(self, image_path):# Run inferencebatch_img = self.preprocess(image_path)predictions = self.model.predict(batch_img)2 unmodified linesresults = keras.backend.ctc_decode(predictions, input_length=input_len, greedy=True)[0][0]# Map indices to characterstext = ""for res in results[0]:if res != -1:text += self.vocab[int(res)]return text# Initializeocr = QalamNet()# Predict# text = ocr.predict("sample_arabic_text.png")# print(f"Predicted Text: {text}")```## 🧠 Model ArchitectureQalam-Net employs a specialized **CNN-BiLSTM-Attention** pipeline:- **Spatial Features**: 3-block CNN with BatchNormalization.- **Sequence Context**: Stacked Bidirectional LSTMs.- **Focus Mechanism**: Self-attention layer to resolve overlapping Arabic characters.- **Loss**: Trained using Connectionist Temporal Classification (CTC).---**Developed by [Ali Khalid](https://github.com/Ali0044)**5 unmodified lines67891011121314151617187 unmodified lines26272829303132333435363738394041424344454647484950515253545556572 unmodified lines60616263646566676869707172737475767778795 unmodified lines- arabic- keras- jax- tensorflow- pytorch---# Qalam-Net (قلم-نت): Advanced Arabic OCRQalam-Net is a high-performance, cross-backend Optical Character Recognition (OCR) model for Arabic. Built on **Keras 3**, it supports **JAX**, **PyTorch**, and **TensorFlow** backends for seamless deployment across any infrastructure.## 🚀 Quick Start (Advanced Usage)7 unmodified lines### 2. Implementation```pythonimport osos.environ["KERAS_BACKEND"] = "jax" # Switch to "tensorflow" or "torch" if preferredimport kerasimport numpy as npimport cv2from huggingface_hub import hf_hub_downloadclass QalamNet:def __init__(self, repo_id="Ali0044/Qalam-Net"):# Download and load the latest model from Hugging Faceprint(f"Fetching model from {repo_id}...")model_path = hf_hub_download(repo_id=repo_id, filename="model.keras")self.model = keras.saving.load_model(model_path)# Standard Arabic Vocabularyself.vocab = [' ', '!', '"', '#', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '=', '?', '[', ']', 'ء', 'آ', 'أ', 'ؤ', 'إ', 'ئ', 'ا', 'ب', 'ة', 'ت', 'ث', 'ج', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'س', 'ش', 'ص', 'ض', 'ط', 'ظ', 'ع', 'غ', 'ـ', 'ف', 'ق', 'ك', 'ل', 'م', 'ن', 'ه', 'و', 'ى', 'ي', 'ً', 'ٌ', 'ٍ', 'َ', 'ُ', 'ِ', 'ّ', 'ْ', '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']def preprocess(self, image_path):img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)img = cv2.resize(img, (128, 32))img = (img / 255.0).astype(np.float32)img = img.Timg = np.expand_dims(img, axis=-1)return np.expand_dims(img, axis=0)def predict(self, image_path):batch_img = self.preprocess(image_path)predictions = self.model.predict(batch_img)2 unmodified linesresults = keras.backend.ctc_decode(predictions, input_length=input_len, greedy=True)[0][0]# Map indices to characterstext = "".join([self.vocab[int(res)] for res in results[0] if res != -1])return text# Usage# ocr = QalamNet()# print(f"Predicted: {ocr.predict('image.png')}")```## 🧠 Model ArchitectureQalam-Net employs a specialized **CNN-BiLSTM-Attention** pipeline:- **Spatial Features**: 3-block CNN for robust feature extraction.- **Sequence Context**: Dual Bidirectional LSTMs to capture Arabic script flow.- **Focus Mechanism**: Self-attention layer for character-level precision.- **Decoding**: Connectionist Temporal Classification (CTC).---**Developed by [Ali Khalid](https://github.com/Ali0044)**
README.md+18-26