Implementation of CNN
Hello there tech-enthusiasts!
From a very young age, we have been taught that we need to apply things that we learn. And we agree with it a one hundred percent. Knowing what convolutional neural network is not enough. You need to know how to implement it.
Implementation of CNN using Keras on MNISTdata set, sounds too science-y right. But trust me it is fun.MNIST is a dataset that is widely used for the study of image classification.
It contains images of handwritten digits from 0 to 9. It is divided into 60,000 training images and 10,000 testing images. Tensor flow and Keras allow us to download This dataset directly using API.
Download the dataset using API.
Here’s the code:
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
import matplotlib.pyplot as plt
image_index = 7777 # You may select anything up to 60,000
print(y_train[image_index]) # The label is 8
plt.imshow(x_train[image_index], cmap='Greys')
plt.show()
We will use only two lines of code to import TensorFlow and download the MNIST dataset under the Keras API. We will assign the data into train and test sets. x_train and x_test parts contain grayscale RGB codes (from 0 to 255) while y_train and y_test parts contain labels from 0 to 9. We shall visualize the images using the ‘matplotlib’ library.
This is how it is going to look when you plot the points.
Data is downloaded from
https://s3.amazonaws.com/img-datasets/mnist.npz
The regular neural network works it’s magic and the number is 8.
Data is downloaded from
https://s3.amazonaws.com/img-datasets/mnist.npz
The regular neural network works it’s magic and the number is 8.
This is what happens. The handwritten numbers go through the network training and are classified into digits.
Happy coding!
Follow us for more interesting projects!

Comments
Post a Comment