<jupyter_start><jupyter_text>This guide trains a neural network model to classify images of clothing, like sneakers and shirts.<jupyter_code># TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)<jupyter_output>2.2.0<jupyter_text>Import the Fashion MNIST dataset<jupyter_code>fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
32768/29515 [=================================] - 0s 1us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] - 2s 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<jupyter_text>Loading the dataset returns four NumPy arrays:* The `train_images` and `train_labels` arrays are the training set—the data the model uses to learn.* The model is tested against the test set, the `test_images`, and `test_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:| Lable | Class       ||-------|-------------|| 0     | T-shirt/top || 1     | Trouser     || 2     | Pullover    || 3     | Dress       || 4     | Coat        || 5     | Sandel      || 6     | Shirt       || 7     | Sneaker     || 8     | Bag         || 9     | Ankle boot  |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:<jupyter_code>class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']<jupyter_output><empty_output><jupyter_text>The following shows there are 60,000 images in the training set, with each image represented as 28 x 28 pixels:<jupyter_code>train_images.shape<jupyter_output><empty_output><jupyter_text>Likewise, there are 60,000 labels in the training set:<jupyter_code>len(train_labels)<jupyter_output><empty_output><jupyter_text>Each label is an integer between 0 and 9:<jupyter_code>train_labels<jupyter_output><empty_output><jupyter_text>There are 10,000 images in the test set. Again, each image is represented as 28 x 28 pixels:<jupyter_code>test_images.shape<jupyter_output><empty_output><jupyter_text>And the test set contains 10,000 images labels:<jupyter_code>len(test_labels)<jupyter_output><empty_output><jupyter_text>The data must be preprocessed before training the network. If you inspect the first image in the training set, you will see that the pixel values fall in the range of 0 to 255:<jupyter_code>plt.figure()
plt.imshow(train_images[0])
plt.colorbar()
plt.grid(False)
plt.show()<jupyter_output><empty_output><jupyter_text>Scale these values to a range of 0 to 1 before feeding them to the neural network model. To do so, divide the values by 255. It's important that the *training set* and the *testing set* be preprocessed in the same way:<jupyter_code>train_images = train_images / 255.0
test_images = test_images / 255.0<jupyter_output><empty_output><jupyter_text>To verify that the data is in the correct format and that you're ready to build and train the network, let's display the first 25 images from the *training set* and display the class name below each image.<jupyter_code>plt.figure(figsize=(10,10))
for i in range(25):
    plt.subplot(5, 5, i+1)
    plt.xticks([])
    plt.yticks([])
    plt.grid(False)
    plt.imshow(train_images[i], cmap=plt.cm.binary)
    plt.xlabel(class_names[train_labels[i]])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13202112337974076, 'fraction_numerical': 0.03504560729716755, 'mean_word_length': 4.99568345323741, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '524054', 'license': 'MIT', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1304, 'n_words': 399, 'path': 'tensor-fashion.ipynb', 'repo_name': '3SUM/vision', 'size': '4166'}