# -*- coding: utf-8 -*-
"""Digit_Recognization.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/github/Shashwat-k/Digit_Recognization/blob/main/Digit_Recognization.ipynb
"""

import tensorflow as tf

mnist = tf.keras.datasets.mnist

(x_train , y_train) , (x_test , y_test) = mnist.load_data()

import matplotlib.pyplot as plt

x_train = tf.keras.utils.normalize(x_train,axis = 1 )
x_test = tf.keras.utils.normalize(x_test,axis = 1 )

x_train[0] , y_train[0]

model = tf.keras.models.Sequential()

model.add(tf.keras.layers.Flatten())

model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))

model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))

model.compile(optimizer='Adam', loss='sparse_categorical_crossentropy' , metrics=['accuracy'])

model.fit(x_train,y_train,epochs=10)

val_loss , val_accu = model.evaluate(x_test,y_test)

predictions = model.predict(x_test)

import numpy as np
print(np.argmax(predictions[1]))

plt.imshow(x_test[0])

