Basic classification- Classify images of clothing Complete Source Code
In this post I show you the basics of tensorflow on MNST dataset. This is part 1 of my upcoming series. So Please subscribe to my newslatter for more.
This guide trains a neural network model to classify images of clothing, like sneakers and shirts. It's okay if you don't understand all the details; this is a fast-paced overview of a complete TensorFlow program with the details explained as you go.
Import The Fashion MNIST Dataset
This guide uses the Fashion MNIST dataset which contains 70,000 grayscale images in 10 categories. The images show individual articles of clothing at low resolution (28 by 28 pixels), as seen here:
Fashion MNIST is intended as a drop-in replacement for the classic MNIST dataset—often used as the "Hello, World" of machine learning programs for computer vision. The MNIST dataset contains images of handwritten digits (0, 1, 2, etc.) in a format identical to that of the articles of clothing you'll use here.
This guide uses Fashion MNIST for variety, and because it's a slightly more challenging problem than regular MNIST. Both datasets are relatively small and are used to verify that an algorithm works as expected. They're good starting points to test and debug code.
Here, 60,000 images are used to train the network and 10,000 images to evaluate how accurately the network learned to classify images. You can access the Fashion MNIST directly from TensorFlow.
Loading the dataset returns four NumPy arrays:
The
train_images
andtrain_labels
arrays are the training set—the data the model uses to learn.The model is tested against the test set, the
test_images
, andtest_labels
arrays.
The images are 28x28 NumPy arrays, with pixel values ranging from 0 to 255. The labels are an array of integers, ranging from 0 to 9. These correspond to the class of clothing the image represents.
Each image is mapped to a single label. Since the class names are not included with the dataset, store them here to use later when plotting the images:
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
Explore The Data
The Rest of the article is under paid subscription, please subscribe to the newsletter and get access to hundreds of source codes of the different projects, and also to all of my explanation articles. This payment also helps me pay my tuition fees. So please if you can subscribe, do subscribe.