Library for SVHN Dataset

nipun deelaka
3 min readMar 11, 2022

Introduction of SVHN dataset based preprocessing and annotation converting python library

Photo by Sven Mieke on Unsplash

PyPi latest release of the svhnL library

Library Documentation

Introduction to the svhnL

The story behind creating a library only based SVHN dataset like this. As a Team, we did some research projects on multi-digit recognition (MDR), which mainly interested in the SVHN dataset and RacingBib dataset. However, as we experience, using the the SVHN dataset is not straightforward as the usual object detection dataset.

Mainly because its published annotation format, does not drop under the formal annotation formats such as COCO, PascalVOC, etc.[reference for more info in image annotation ] To matter make worst the .mat file, that contains annotation does not support most of the .mat file reading python libraries, and most of the example codes in the Github and StackOverflow related to SVHN dataset annotation conversion makes errors. Furthermore, As initially said in the case of use in popular object detection models like YoLoV4 is not straightforward and time-consuming. Also, the MDR model like the Deep Recurrent Attention model (DRAM)does not directly support it. So, introducing library target to resolve almost all issues stated above.

Functionalities Provides

  1. Download Dataset

SVHN dataset published in mainly under two categories as three datasets;
categories: Full Image / Cropped Digits
3 Datasets : training dataset [73257 digits] / test dataset [26032 digits] / extra dataset [531131]

The library provides a python interface to download the three datasets under categories of ‘Full Image’ and extract the downloaded ‘.tar.gz’ file into the given directory. The reason behind only providing the ‘Full Image’ category is that; we provide another functionality in the library to generate ‘Cropped Digits’ out of the ‘Full Image’ dataset.

svhnL library download function example

2. Convert Annotations file

This functionality target to solve the issue with current codes for SVHN dataset accessing and converting annotation into another format such as JSON& CSV.
The library provided two main functions in the latest release, which intended to convert to mat-to-JSON and mat-to-CSV respectively.

svhnL library ann_to_json function example
svhnL library ann_to_csv function example

3. Build numpy dataset with directly applicable annotation set

Mainly, there are two kind of usages in SVHN dataset in MDR field as stated in the introduction.

Firstly model predicts fix number of digits present in the scene and therefore the feeding dataset has to be in shape with the model’s [Deep Recurrent Attention model (DRAM)] input. there has to be done several digit present filtering operation [with lower and upper limits] and drop bounding box present in the initial annotation file and generate metrics of output digits. As good news, these are all the operations handled by the introducing library, while you have to set parameters orderly.

The second format target for general objection model like YoLoV4; where the annotation file has to be in a general format such as PascalVOC, COCO, CSV, etc. The library supports only the CoCo format [A JSON file as annotation]. But you could convert it into any general annotation format by using another python library called ImgAnn. The output annotation file from this library is directly supported by the ImgAnn library. Also, the number digits restriction is valid in this method as well.

svhnL library gen_dataset 2nd example

As a bonus, the above functionality resizes all the images into common size, provides a numpy tensor, also you can set the parameter to save to results automatically. Not only that the functionality supports RGB to gray-scale conversion as well.

We welcome any improvement or issue of the current version. you can reach as through GitHub.
Happy pythonic !

--

--