Activity 1 - Importing the TensorFlow library and datasets

Workshop Resources

Import Dependencies


The first thing we have to do is to import the TensorFlow library in order to use functions that will allow us to train your model.

We will also be implementing plots to visualize the prediction of our model, so for that we need to import the following libraries:

# Importing TensorFlow and tf.keras libraries

import tensorflow as tf
from tensorflow import keras 

# Helper libraries for statistics and plotting

import numpy as np
import matplotlib.pyplot as plt 

These libraries are essential as they are a collection of precompiled methods and functions that and importing them into our program allows us to access these methods without having to rewrite these entire libraries. For example, we import the methods and functions to TensorFlow and NumPy to avoid having to write the entirety of these programs within our own program.

Load Datasets

Now, we want to load the Fashion MNIST dataset, which has the collection of all the images of clothing we need for your model.

#This variable is declared from the fashion_mist library of the datasets section

fashion_mnist = keras.datasets.fashion_mnist 
#This loads four variables from the dataset. 
#The train_images and train_labels are data that the model uses to learn
#The test_images and test_labels are used by the model to compare against.

(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() 

You might notice we are splitting the data into training and testing datasets with their corresponding labels. A training dataset is for our model to learn about the optimal parameters to achieve our tasks, while the test dataset is to validate how well our model has learned. This is just like how we learn things: we’re being continuously trained and tested to get better!

Prepare Our Data

The next step is to create a list of categories under the variable class_names.

Your supervisor gives you the categories of apparel that the warehouse processes. This will be created under the variable class_names.

Not sure how to create a list in Python?

Task 1

Write the following class names in the list class_names:

  • T-shirt/top
  • Trouser
  • Pullover
  • Dress
  • Coat
  • Sandal
  • Shirt
  • Sneaker
  • Bag
  • Ankle boot

Optional Reading

If you are interested in learning about these libraries in more detail, feel free to visit the following websites.

Learn about TensorFlow

Learn about NumPy

Learn about Matplotlib