<jupyter_start><jupyter_text>In the videos you looked at how you would improve Fashion MNIST using Convolutions. For your exercise see if you can improve MNIST to 99.8% accuracy or more using only a single convolutional layer and a single MaxPooling 2D. You should stop training once the accuracy goes above this amount. It should happen in less than 20 epochs, so it's ok to hard code the number of epochs for training, but your training must end once it hits the above metric. If it doesn't, then you'll need to redesign your layers.I've started the code for you -- you need to finish it!When 99.8% accuracy has been hit, you should print out the string "Reached 99.8% accuracy so cancelling training!"<jupyter_code>import tensorflow as tf
from tensorflow import keras
mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0
class myCallBacks(keras.callbacks.Callback):
    def on_epoch_end(self,epoch,logs={}):
        if(logs.get('acc')>0.998):
            self.model.stop_training=True
def train_mnist_conv():
    callbacks=myCallBacks()

    model=keras.models.Sequential([
        keras.layers.Conv2D(64,(3,3),input_shape=(28,28,1)),
        keras.layers.MaxPooling2D(2,2),
        keras.layers.Flatten(),
        keras.layers.Dense(128,activation='relu'),
        keras.layers.Dense(10,activation='softmax')
    ])

    model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy',
                  metrics=['acc'])
    history=model.fit(training_images,training_labels,epochs=20,callbacks=[callbacks])
    
    return history.epoch, history.history['acc'][-1]
train_mnist_conv()<jupyter_output>Train on 60000 samples
Epoch 1/20
60000/60000 [==============================] - 19s 314us/sample - loss: 0.1642 - acc: 0.9502
Epoch 2/20
60000/60000 [==============================] - 16s 270us/sample - loss: 0.0596 - acc: 0.9811
Epoch 3/20
60000/60000 [==============================] - 16s 272us/sample - loss: 0.0351 - acc: 0.9888
Epoch 4/20
60000/60000 [==============================] - 16s 264us/sample - loss: 0.0249 - acc: 0.9915
Epoch 5/20
60000/60000 [==============================] - 17s 285us/sample - loss: 0.0178 - acc: 0.9941
Epoch 6/20
60000/60000 [==============================] - 20s 329us/sample - loss: 0.0142 - acc: 0.9950
Epoch 7/20
60000/60000 [==============================] - 17s 287us/sample - loss: 0.0133 - acc: 0.9955
Epoch 8/20
60000/60000 [==============================] - 17s 287us/sample - loss: 0.0103 - acc: 0.9967
Epoch 9/20
60000/60000 [==============================] - 22s 375us/sample - loss: 0.0095 - acc: 0.9968
Epoch 10/20
60000/60000 [================[...]
{'fraction_non_alphanumeric': 0.20549374130737136, 'fraction_numerical': 0.1168289290681502, 'mean_word_length': 4.25, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '459786', 'license': 'MIT', 'n_tokens_mistral': 1181, 'n_tokens_neox': 922, 'n_words': 254, 'path': 'TensorFlow/Learn_by_deeplearning.ai/Course 1 - TensorFlow for AI, ML and DL/Labs/Week3/C1-W3-assignment-CNN-Fashion MNIST.ipynb', 'repo_name': 'tsuirak/skills', 'size': '2876'}