<jupyter_start><jupyter_text>Handwriting MNIST recognization<jupyter_code>import tensorflow as tf
from os import path, getcwd, chdir
import matplotlib.pyplot as plt
from keras.datasets import mnist<jupyter_output><empty_output><jupyter_text><jupyter_code>(x_train, y_train), (x_test, y_test) = mnist.load_data()
print("x_train_shape:{}, y_train_shape:{}".format(x_train.shape, y_train.shape))
print("x_test_shape:{}, y_test_shape:{}".format(x_test.shape, y_test.shape))
for i in range(8):
    plt.subplot(240+1+i)
    plt.imshow(x_train[i])
plt.show()
class myCallback(tf.keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs={}):
        if(logs.get('accuracy')>0.99):
            print("\nReached 99% accuracy so cancelling training!")
            self.model.stop_training = True
x_train, x_test = x_train / 255.0, x_test / 255.0
 model = tf.keras.models.Sequential([
      tf.keras.layers.Flatten(input_shape=(28, 28)),
      tf.keras.layers.Dense(128, activation=tf.nn.relu),
      tf.keras.layers.Dense(10, activation=tf.nn.softmax)
    ])
model.compile(optimizer="adam", loss="SparseCategoricalCrossentropy", metrics=["accuracy"])
callbacks = myCallback()
history = model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test), callbacks=[callbacks])
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))

plt.plot(epochs, acc, 'r', label='Training accuracy')
plt.plot(epochs, val_acc, 'b', label='Validation accuracy')
plt.title('Training and validation accuracy')
plt.legend()
plt.show()

plt.plot(epochs, loss, 'r', label='Training Loss')
plt.plot(epochs, val_loss, 'b', label='Validation Loss')
plt.title('Training and validation loss')
plt.legend()

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15806626833242804, 'fraction_numerical': 0.015752308527973928, 'mean_word_length': 6.084615384615384, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '118129', 'license': 'MIT', 'n_tokens_mistral': 701, 'n_tokens_neox': 669, 'n_words': 120, 'path': 'Handwriting_MNIST.ipynb', 'repo_name': 'harshitamotwani/Computer_vision_TF', 'size': '1841'}