File size: 3,355 Bytes
1d55706
 
 
fde3f5a
 
 
779f9f8
 
ef43732
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fde3f5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
license: apache-2.0
pipeline_tag: image-classification
---
# Devanagari Character Recognition

[**<span style="color:red">Want to try this model? Click here!</span>**](https://huggingface.co/spaces/krishnamishra8848/devanagari_character_recognition)

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!

```python
# 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}")