Downloads · 30 days
0
arpit-gour02/devanagari-character-recognition
devanagari-character-recognition is a image classification model from arpit-gour02. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
This repository contains a custom Convolutional Neural Network (CNN) trained from scratch to recognize 46 classes of handwritten Devanagari characters and digits. The model is implemented in PyTorch and achieves appro…
Downloads · 30 days
0
Access
Public
Updated Dec 30, 2025
Repo size
8.6 MB
Likes
1
Public
Click a slice to open those files.
.png4.5 MB · 51%
From the Hugging Face model README
This repository contains a custom Convolutional Neural Network (CNN) trained from scratch to recognize 46 classes of handwritten Devanagari characters and digits. The model is implemented in PyTorch and achieves approximately 98.42% test accuracy on the Devanagari Handwritten Character Dataset (DHCD).
The architecture is intentionally designed for small fixed-size inputs, aggressively reducing spatial dimensions to 1×1 before classification to enforce global feature learning.
Layer progression:

Dataset: Devanagari Handwritten Character Dataset (DHCD)
Total Images: ~92,000
Classes: 46
Image Size: 32×32 pixels
Color Space: Grayscale
Writers: Multiple native writers

The dataset was split in a class-balanced manner:
Each split preserves an approximately equal number of samples per class. The validation set was used for convergence monitoring and hyperparameter tuning, while the test set was held out entirely for final evaluation.

The model performs consistently well across most characters, with minor confusion only between visually similar glyphs.
⚠️ Important: Because this is a custom architecture, the model class must be defined exactly as used during training before loading the weights.
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.transforms as transforms
from PIL import Image
class ModelA(nn.Module):
def __init__(self, num_classes=46):
super().__init__()
self.conv1 = nn.Conv2d(1, 64, 5)
self.lrn1 = nn.LocalResponseNorm(5)
self.pool1 = nn.MaxPool2d(2)
self.conv2 = nn.Conv2d(64, 128, 5)
self.lrn2 = nn.LocalResponseNorm(5)
self.pool2 = nn.MaxPool2d(2)
self.conv3 = nn.Conv2d(128, 256, 5)
self.lrn3 = nn.LocalResponseNorm(5)
self.dropout = nn.Dropout(0.5)
self.fc = nn.Linear(256, num_classes)
def forward(self, x):
x = self.pool1(F.relu(self.lrn1(self.conv1(x))))
x = self.pool2(F.relu(self.lrn2(self.conv2(x))))
x = F.relu(self.lrn3(self.conv3(x)))
x = x.view(x.size(0), -1)
x = self.dropout(x)
return self.fc(x)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = ModelA().to(device)
model.load_state_dict(torch.load("dhcd-model.pth", map_location=device))
model.eval()
To reproduce results:
dhcd.ipynb notebookDevanagari Handwritten Character Recognition using a Custom CNN,
Arpit Gaur, 2025
Released under the MIT License.