Devanagari Character Recognition
Want to try this model? Click here!
Devanagari Character Recognition Model This repository contains a TensorFlow-based deep learning model designed for recognizing Devanagari script characters and digits. The model is trained on a dataset containing 46 unique classes, including characters from "क" to "ज्ञ" and digits from ० to ९. It achieves a high validation accuracy of 98.1% and demonstrates robust performance across all classes.
Model Details Model Type: Convolutional Neural Network (CNN) Input Shape: 32x32 grayscale images Number of Classes: 46 (36 characters + 10 digits) Framework: TensorFlow File: saved_model.keras
Performance Metrics Metric Value Validation Accuracy 98.1% Validation Loss 0.0777 Macro Precision 98% Macro Recall 98% Macro F1-score 98%
Strengths: High precision and recall across most classes, especially for digits (०–९). Robust generalization for complex characters like त्र and ज्ञ. Weaknesses: Slightly lower recall for characters like छ and थ, likely due to similarity with other classes. Minor misclassifications in noisy or poorly written input images.
How to Contribute If you'd like to contribute:
Improve the model architecture or hyperparameters. Add new features, such as support for vowels or additional classes. Report issues or bugs. Feel free to open a pull request or create an issue!
# Example Code: You can test our model in Google Colab or Any where you want
import requests
from tensorflow.keras.models import load_model
# Download the model from Hugging Face
url = "https://huggingface.co./krishnamishra8848/Devanagari_Character_Recognition/resolve/main/saved_model.keras"
model_path = "saved_model.keras"
response = requests.get(url)
with open(model_path, "wb") as f:
f.write(response.content)
# Load the model
model = load_model(model_path)
# Nepali characters mapping
label_mapping = [
"क", "ख", "ग", "घ", "ङ", "च", "छ", "ज", "झ", "ञ",
"ट", "ठ", "ड", "ढ", "ण", "त", "थ", "द", "ध", "न",
"प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श",
"ष", "स", "ह", "क्ष", "त्र", "ज्ञ", "०", "१", "२", "३",
"४", "५", "६", "७", "८", "९"
]
# File upload
uploaded = files.upload()
# Process the uploaded image
for filename in uploaded.keys():
# Load the image
img = Image.open(filename)
# Convert the image to grayscale if necessary
img = np.array(img)
if len(img.shape) == 3: # If the image is RGB
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
# Resize to 32x32
img_resized = cv2.resize(img, (32, 32))
# Normalize the pixel values
img_normalized = img_resized.astype("float32") / 255.0
# Reshape to match the model's input shape
img_input = img_normalized.reshape(1, 32, 32, 1)
# Make a prediction
prediction = model.predict(img_input)
predicted_class_index = np.argmax(prediction)
# Get the predicted Nepali character
predicted_character = label_mapping[predicted_class_index]
print(f"Predicted Character: {predicted_character}")
- Downloads last month
- 12