Hands On: Keras Playground
Now that you have some Keras under your belt, here is an exercise for you: take the MNIST network we built in Part II of this book and rewrite it from scratch using Keras.
Keras already comes with a few common datasets, MNIST included—so you don’t have to use our mnist.py library. Instead, you can load MNIST and one-hot encode its labels with this piece of code:
| from keras.datasets import mnist |
| from keras.utils import to_categorical |
| |
| (X_train_raw, Y_train_raw), (X_test_raw, Y_test_raw) = mnist.load_data() |
| X_train = X_train_raw.reshape(X_train_raw.shape[0], -1) / 255 |
| X_test = X_test_raw.reshape(X_test_raw.shape[0], -1) / 255 |
| Y_train = to_categorical(Y_train_raw) |
| Y_test = to_categorical(Y_test_raw) ... |
Get Programming Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.