Still with old digits MNIST? Hello, Hindi Characters MNIST!

Tushar Tiwari
2 min readMay 11, 2023

Introduction

We all might have used the classic MNIST dataset of containing 10 handwritten digits. Its often used as the introduction to image classification problem.

Let’s try a different dataset for same problem of image classification. This time using Hindi Characters MNIST. It contains 36 categories for characters in Hindi language.

Dataset source form Kaggle . Thanks to imbikramsaha .

Sample batch of data

Quickly build a Classifier using FASTAI

Images are stored in folder name which corresponds to the character name (category). We have a total of 10800 images in the dataset.

Each image is of size 32*32.

Lets define a helper fucntion which returns the parent folder name of a file which will be used in image dataloader:

def class_name(file):
return file.parent.name

Creating Image dataloader


dls = ImageDataLoaders.from_path_func(path, files, label_func =class_name ,
item_tfms=Resize(32))

files: Get image files in path recursively. eg:

files[0]
Path('/kaggle/input/hindicharacters/hindi-character-S/kna/92306.png')

lable_func : function that receives a file name and outputs class label. Here we will use the class_name function defined above.

item_tfms: Transformation applied to each image before batching. Here we have just use the Resize(32) as transformation.

Build an vison_learner

We will be using pretained resnet34 model.And do a 1 epoch of fine tunning to check is everything is working as expected.

learn = vision_learner(dls, resnet34, metrics=[error_rate,accuracy], model_dir="/tmp/model/")
learn.fine_tune(1)

Then do training for 5 epochs to let model converge.

learn.fine_tune(5, 4e-3)

Results we got after training to a accuracy of 93.8% on validation set.

Above is the batch of predictions results.

Interpretation

Lets find out the places where the model failed to predict.

interp = Interpretation.from_learner(learn)
interp.plot_top_losses(9, figsize=(15,10))

Frankly these letters are not easy even for a native hindi speaker.

Reference:

Dataset source form Kaggle.

If you wants to play around checkout my kaggle notebook.

If you want to get in touch with me:

Contact: Linkedin ||| Email

--

--

Tushar Tiwari

Finding insights from data | Fascinated by how Markets works.