AN 1011: TinyML Applications in Altera FPGAs Using LiteRT for Microcontrollers

ID 848984
Date 4/07/2025
Public
Document Table of Contents

2.2.1. Preparing Dataset

Apply the following Python commands to load the MNIST dataset. The Matplotlib library allows you to display random MNIST samples.
# Load the MNIST Train and Test Dataset
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()

rows, cols = 28, 28

# Display Random Samples
fig = plt.figure(figsize=(9,9))
for i in range(8):
  ind = random.randint(0, len(x_train))
  plt.subplot(3,3,i+1)
  plt.imshow(x_train[ind], cmap="gray", interpolation=None)
  plt.title(y_train[ind])
Figure 1. Example of MNIST Samples