In the previous article, we discussed about image classification using GluonCV on a pretrained network. In this article, we will discuss how to implement a binary image classifier by training LeNet by bringing different components of gluoncv together such as autograd, trainer, dataset, and dataloader, to train a LeNet network. We can accomplish this is by writing a training loop.

  1. Import Libraries

We first import the libraries. We initialize mxnet.init for more parameter initialization methods, matplotlib for drawing, time for benchmarking as well as other gluon packages.

from mxnet import nd, gluon, init, autograd, metric
from mxnet.gluon import nn
from mxnet.gluon.data.vision import datasets, transforms

import matplotlib.pyplot as plt
from time import time

2. Data

We will use **_fashion m-nest _**dataset for training.

2.1 Load Data:

Fashion m-nest dataset is automatically downloaded through gluonsdata.vision.datasets module. The dataset can be downloaded using the following code. It also shows the properties of the first example.

mnist_train = datasets.FashionMNIST(train=True)
x, y = mnist_train[0]

print('X shape: %s dtype : %s' % (x.shape, x.dtype))
print('Number of images: %d'%len(mnist_train))

Image for post

Each example in this dataset is a 28 by 28 sides gray image which is presented as an NDRA with the shape format of height X width X channel. The label is a scalar.

#neural-networks #lenet-5 #deeplearing #gluoncv #image-classification #neural networks

LeNet for Image Classification using GluonCV
1.90 GEEK