
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can TensorFlow be used to download and explore the Fashion MNIST dataset using Python?
Tensorflow is a machine learning framework that is provided by Google. It is an open−source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes.
The ‘tensorflow’ package can be installed on Windows using the below line of code −
pip install tensorflow
The ‘Fashion MNIST’ dataset contains images of clothing of different kinds. It contains grayscale images of more than 70 thousand clothes that belong to 10 different categories. These images are of low resolution (28 x 28 pixels).
We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.
Following is the code −
Example
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt print("The tensorflow version used is ") print(tf.__version__) print("The dataset is being loaded") fashion_mnist = tf.keras.datasets.fashion_mnist print("The dataset is being classified into training and testing data ") (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] print("The dimensions of training data ") print(train_images.shape) print("The number of rows in the training data") print(len(train_labels)) print("The column names of dataset") print(train_labels) print("The dimensions of test data ") print(test_images.shape) print("The number of rows in the test data") print(len(test_labels))
Code credit − https://www.tensorflow.org/tutorials/keras/classification
Output
The tensorflow version used is 2.4.0 The dataset is being loaded The dataset is being classified into training and testing data Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 32768/29515 [=================================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz 26427392/26421880 [==============================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz 8192/5148 [===============================================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz 4423680/4422102 [==============================] - 0s 0us/step The dimensions of training data (60000, 28, 28) The number of rows in the training data 60000 The column names of dataset [9 0 0 ... 3 0 5] The dimensions of test data (10000, 28, 28) The number of rows in the test data 10000
Explanation
The required packages are imported.
The version of Tensorflow being used is determined.
The Fashion MNIST dataset is loaded, and the Fashion MNIST dataset can be accessed directly from TensorFlow.
Next, the data is split into training and testing datasets.
There are totally 70000 rows in the dataset, out of which 60k images are used for training and 10k is used to evaluate how well the model has learnt to classify the images into different labels.
This is a classification problem wherein every image from the dataset is given a specific label.
These images are of clothing, and respective labels are assigned to them.
The shape, the number of rows in the training and test dataset, and the column names in the dataset are displayed on the console.
- Related Articles
- How can Tensorflow be used to download and explore the Illiad dataset using Python?
- How can Tensorflow be used to download and explore IMDB dataset in Python?
- How can TensorFlow be used to make predictions for Fashion MNIST dataset in Python?
- How can TensorFlow be used to build the model for Fashion MNIST dataset in Python?
- How can TensorFlow be used to train the model for Fashion MNIST dataset in Python?
- How can TensorFlow be used to preprocess Fashion MNIST data in Python?
- How can Tensorflow and Python be used to download and prepare the CIFAR dataset?
- How can Tensorflow be used to explore the flower dataset using keras sequential API?
- How can Tensorflow be used to explore the dataset and see a sample file from the stackoverflow question dataset using Python?
- How can Tensorflow be used to save and load weights for MNIST dataset?
- How can TensorFlow be used to verify the predictions for Fashion MNIST in Python?
- How can Tensorflow be used to define a model for MNIST dataset?
- How can Tensorflow be used to download the flower dataset using keras sequential API?
- How can Tensorflow be used to download flower dataset into the environment?
- How can Tensorflow be used with Fashion MNIST dataset so that the trained model is used to predict a different image in Python?
