Looking at and Loading Data
Subscribe to Tech with Tim
Installing Tensorflow 2.0
Before we can start loading in the data that we will feed our neural network we must install tensorflow 2.0. If you are on windows it is as easy as typing the following (this is the cpu version):
pip install -q tensorflow==2.0.0-alpha0
If you are having any troubles try following the instructions on the tensorflow website.
Installing MatPlotLib
The last thing to install is MatPlotLib. If you are unfamiliar with matplotlib it is a python module that allows us to visualize and graph data. Install it with the pip command below:
pip install matplotlib
The Importance of Data
Data is by far the most important part of any neural network. Choosing the right data and transforming it into a form that the neural network can use and understand is vital and will affect the networks performance. This is because the data we pass the network is what it will use to modify its weights and biases!
Keras Datasets
In these first few tutorials we will simply use some built in keras datasets which will make loading data fairly easy. The dataset we will use to start is the Fashion MNIST datset. This dataset contains 60000 images of different clothing/apparel items. The goal of our network will be to look at these images and classify them appropriately To load our first dataset in we will do the following:
import tensorflow as tf from tensorflow import keras import numpy as np import matplotlib.pyplot as plt data = keras.datasets.fashion_mnist
Now we will split our data into training and testing data. It is important that we do this so we can test the accuracy of the model on data it has not seen before.
(train_images, train_labels), (test_images, test_labels) = data.load_data()
Finally we will define a list of the class names and pre-process images. We do this by dividing each image by 255. Since each image is greyscale we are simply scaling the pixel values down to make computations easier for our model.
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] train_images = train_images/255.0 test_images = test_images/255.0
Full Code
import tensorflow as tf from tensorflow import keras import numpy as np import matplotlib.pyplot as plt data = keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = data.load_data() class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] train_images = train_images/255.0 test_images = test_images/255.0