<jupyter_start><jupyter_text>Training PhaseWe are going to use [tf.keras](https://www.tensorflow.org/guide/keras). tf.keras is a high-level API to build and train models in Tensorflow.<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__)
fashion_mnist = keras.datasets.fashion_mnist

(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']
num_classes = 10

# input image dimensions
img_rows, img_cols = 28, 28
%matplotlib inline

plt.figure()
plt.imshow(train_images[0])
plt.colorbar()
plt.grid(False)
train_images = train_images / 255.0

test_images = test_images / 255.0
# model = keras.Sequential([
#     keras.layers.Flatten(input_shape=(28, 28)),
#     keras.layers.Dense(128, activation=tf.nn.relu),
#     keras.layers.Dense(10, activation=tf.nn.softmax)
# ])
train_images = train_images.reshape(train_images.shape[0], img_rows, img_cols, 1)
test_images = test_images.reshape(test_images.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1)
model = keras.Sequential([
    keras.layers.Conv2D(32, kernel_size=(3, 3), 
                        activation=tf.nn.relu, 
                        input_shape=input_shape,
                        data_format='channels_last'),
    keras.layers.Conv2D(64, (3, 3), activation=tf.nn.relu),
    keras.layers.MaxPool2D(pool_size=(2, 2)),
    keras.layers.Dropout(0.25),
    keras.layers.Flatten(),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dropout(0.5),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer="Adadelta", 
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.summary()
batch_size = 128
epochs = 100
file_writer = tf.summary.FileWriter('logs', tf.keras.backend.get_session().graph)
model.fit(train_images, train_labels, batch_size=batch_size, epochs=epochs)
test_loss, test_acc = model.evaluate(test_images, test_labels)

print('Test accuracy:', test_acc)
# Save entire model to a HDF5 file
model.save('fashion_mnist.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13485566566135287, 'fraction_numerical': 0.025850926324859975, 'mean_word_length': 4.362586605080831, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '214601', 'license': 'Apache-2.0', 'n_tokens_mistral': 874, 'n_tokens_neox': 822, 'n_words': 154, 'path': 'training/training_fashion_mnist-channels_last.ipynb', 'repo_name': 'rhezaharliman/TFLite_Android_mnfdrawing_detector', 'size': '2321'}