5. Autoencoders
Activity 5.01: The MNIST Neural Network
Solution:
In this activity, you will train a neural network to identify images in the MNIST dataset and reinforce your skills in training neural networks:
- Import
pickle
,numpy
,matplotlib
, and theSequential
andDense
classes from Keras:import pickle import numpy as np import matplotlib.pyplot as plt from keras.models import Sequential from keras.layers import Dense import tensorflow.python.util.deprecation as deprecation deprecation._PRINT_DEPRECATION_WARNINGS = False
- Load the
mnist.pkl
file, which contains the first 10,000 images and corresponding labels from the MNIST dataset that are available in the accompanying source code. The MNIST dataset is a series of 28 x 28 grayscale images of handwritten digits 0 through 9. Extract the images and labels:with open('mnist.pkl', 'rb') as f: Â Â Â Â data = pickle.load(f) images = data['images'] labels = data['labels...