Learn practical skills, build real-world projects, and advance your career

Exploring SVHN using Deep Neural Network

The Street View House Numbers (SVHN) is a real-world image dataset used for developing machine learning and object recognition algorithms. It is one of the commonly used benchmark datasets as It requires minimal data preprocessing and formatting. Although it shares some similarities with MNIST where the images are of small cropped digits, SVHN incorporates an order of magnitude more labelled data (over 600,000 digit images). It also comes from a significantly harder real world problem of recognising digits and numbers in natural scene images. The images lack any contrast normalisation, contain overlapping digits and distracting features which makes it a much more difficult problem compared to MNIST.

Overview

  • 10 classes, 1 for each digit. Digit '1' has label 1, '9' has label 9 and '0' has label 10.
  • 73257 digits for training, 26032 digits for testing, and 531131 additional, somewhat less difficult samples, to use as extra training data

Dataset is taken from http://ufldl.stanford.edu/housenumbers/

import torch
import torchvision
import numpy as np
import matplotlib.pyplot as plt
import torch.nn as nn
import torch.nn.functional as F
from torchvision.datasets import SVHN
from torchvision.transforms import ToTensor
from torchvision.utils import make_grid
from torch.utils.data.dataloader import DataLoader
from torch.utils.data import random_split
%matplotlib inline

Now, We download the data and create a PyTorch dataset using the SVHN class from torchvision.datasets.

dataset = SVHN(root='data/', download=True, transform=ToTensor())
Using downloaded and verified file: data/train_32x32.mat
len(dataset[0])
2