Back to Data Science Ipython Notebooks

ConvNet HandsOn with Keras

deep-learning/keras-tutorial/2.2.1 Supervised Learning - ConvNet HandsOn Part I.ipynb

latest2.3 KB
Original Source

Credits: Forked from deep-learning-keras-tensorflow by Valerio Maggio

ConvNet HandsOn with Keras

Problem Definition

Recognize handwritten digits

Data

The MNIST database (link) has a database of handwritten digits.

The training set has $60,000$ samples. The test set has $10,000$ samples.

The digits are size-normalized and centered in a fixed-size image.

The data page has description on how the data was collected. It also has reports the benchmark of various algorithms on the test dataset.

Load the data

The data is available in the repo's data folder. Let's load that using the keras library.

For now, let's load the data and see how it looks.

python
import numpy as np
import keras
from keras.datasets import mnist
python
!mkdir -p $HOME/.keras/datasets/euroscipy_2016_dl-keras/data/
python
# Set the full path to mnist.pkl.gz
path_to_dataset = "euroscipy_2016_dl-keras/data/mnist.pkl.gz"
python
# Load the datasets
(X_train, y_train), (X_test, y_test) = mnist.load_data(path_to_dataset)

Basic data analysis on the dataset

python
# What is the type of X_train?

python
# What is the type of y_train?

python
# Find number of observations in training data

python
# Find number of observations in test data

python
# Display first 2 records of X_train

python
# Display the first 10 records of y_train

python
# Find the number of observations for each digit in the y_train dataset 

python
# Find the number of observations for each digit in the y_test dataset 

python
# What is the dimension of X_train?. What does that mean?


Display Images

Let's now display some of the images and see how they look

We will be using matplotlib library for displaying the image

python
from matplotlib import pyplot
import matplotlib as mpl
%matplotlib inline
python
# Displaying the first training data
python
fig = pyplot.figure()
ax = fig.add_subplot(1,1,1)
imgplot = ax.imshow(X_train[1], cmap=mpl.cm.Greys)
imgplot.set_interpolation('nearest')
ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('left')
pyplot.show()
python
# Let's now display the 11th record