In: Computer Science
write a fully-connected neural network to work with MNIST and
Tensorflow 2.x. The labels will be input and MNIST image vectors as
output labels. use tf.GradientTape instead fit. show the
28x28 image with the input vector
There is a complete explaination givn below in segaments for fully-connected neural network to work with MNIST and tensorflow 2.x.
This is a fast-paced overviwe of acomplete TensorFlow program with the detail explained as you go.

The above code is given in python.
Import the Fashion MNIST dataset:- Below uses the FASHION MNIST dataset which contains 70000 grayscale image in 10 catagories.The images show individual articles of clothing low resolution (28 by 28 pixels) as seen here -

above fashion mnist used for variety and because its slightly more challenging problem than regular MNIST .Both datasets are relatively small and are used to verify that an algorithm works as expected they are goo starting points to test and debug code.Here, 60,000 images are used to train the network and 10,000 images to evaluate how accurately the network learned to classify images. yu can access the fashion MNIST data directly from tensorflow
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
Loading dataset returns for NumPy arrays:
Image with the input vector:- the images are
28 x 28 Numpy arrays with pixel value ranging from 0 to 255. the
lables are an array of integers ranging from 0 to 9.
| LABLE | CLASS |
| 0 | Tshirt/top |
| 1 | Trouser |
| 2 | Pullover |
| 3 | Dress |
| 4 | Coat |
| 5 | Sandal |
| 6 | Shirt |
| 7 | Sneaker |
| 8 | Bag |
| 9 | Ankle boot |
classnames = ['Tshirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']


:-
The data must be preprocessed before training the network if you
inspect the first image in the training set, you will see the pixel
value fall from 0 to 255.


;-- Record operation for automatics
differentiation.
Operations are recorded if they are executed within this context manager and at least one of their inputs is being watched.
tf.gradientTape(
persistent=False, accessed_variables=True
)
trainable variables are automatically watched..Tensors can be manually watched by invoking the watch method on this context manage.
compile the model- Before the model is ready for training, it requires a few more settings. These are added during the model's compile step:
at last you can train the model .It turns out that the accuracy on the test dataset is a little less than the accuracy on the training dataset. This gap between test accuracy and training accuracy represents overfitting.Overfitting happens when a machine learning model performs worse on new, previously unseen inputs than it does on the training data.aAn overfitted model memorizes the noise and details in the training dataset to a point where it negatively impacts.