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

MNIST digits classification with Keras

We don't expect you to code anything here because you've already solved it with TensorFlow.

But you can appreciate how simpler it is with Keras.

We'll be happy if you play around with the architecture though, there're some tips at the end.

alt
!pip install keras_utils
Collecting keras_utils Downloading keras-utils-1.0.13.tar.gz (2.4 kB) Requirement already satisfied: Keras>=2.1.5 in ./anaconda3/lib/python3.7/site-packages (from keras_utils) (2.4.3) Requirement already satisfied: h5py in ./anaconda3/lib/python3.7/site-packages (from Keras>=2.1.5->keras_utils) (2.8.0) Requirement already satisfied: scipy>=0.14 in ./anaconda3/lib/python3.7/site-packages (from Keras>=2.1.5->keras_utils) (1.4.1) Requirement already satisfied: pyyaml in ./anaconda3/lib/python3.7/site-packages (from Keras>=2.1.5->keras_utils) (5.3) Requirement already satisfied: numpy>=1.9.1 in ./anaconda3/lib/python3.7/site-packages (from Keras>=2.1.5->keras_utils) (1.18.1) Requirement already satisfied: six in ./anaconda3/lib/python3.7/site-packages (from h5py->Keras>=2.1.5->keras_utils) (1.14.0) Building wheels for collected packages: keras-utils Building wheel for keras-utils (setup.py) ... done Created wheel for keras-utils: filename=keras_utils-1.0.13-py3-none-any.whl size=2655 sha256=7734e028891a00a27b22ad1154848c6966f52181f030e32f7d0de7749dc816ed Stored in directory: /home/immanisaurabh/.cache/pip/wheels/d0/dd/3b/493952a5240d486a83805d65360dedadbadeae71d25e2c877f Successfully built keras-utils Installing collected packages: keras-utils Successfully installed keras-utils-1.0.13
import numpy as np
from sklearn.metrics import accuracy_score
from matplotlib import pyplot as plt
%matplotlib inline
import tensorflow as tf
print("We're using TF", tf.__version__)
import keras
print("We are using Keras", keras.__version__)

import sys
sys.path.append("../..")
import keras_utils
#from keras_utils import reset_tf_session
We're using TF 2.2.0 We are using Keras 2.4.3

Look at the data

In this task we have 50000 28x28 images of digits from 0 to 9.
We will train a classifier on this data.