Question

In: Computer Science

write a fully-connected neural network to work with MNIST and Tensorflow 2.x. The labels will be...

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

Solutions

Expert Solution

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:

  • the train images and train lables are the training set the data the model uses to learn.
  • the model is tested against the test set,test images, and est lables 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:

  1. Loss Function
  2. Optimizer
  3. Metrics

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.


Related Solutions

write a fully-connected neural network to work with MNIST and Tensorflow 2.x. The labels will be...
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. PLEASE WRITE CODE AND DO NOT SENT ME DIFFERENT PARTS TO A WEBSITE. It is clear, it's a homework assignment.  
JAVA Program: Train a 3 layer neural network to recognize MNIST handwritten digit set. The network...
JAVA Program: Train a 3 layer neural network to recognize MNIST handwritten digit set. The network must use back propagation and Stochastic Gradient algorithm. NO third party libraries allowed(from scratch). Assume the mnist data is in two csv files: mnist_train.csv and mnist_test.csv. After each training epoch, The program should (1) print out statistics for each of the ten digits, the number of recognized inputs over total number of occurences of that digit (2) the overall accuracy considering all ten digits.
Write a neural network in python for multiclass classification of an imbalanced dataset that makes a...
Write a neural network in python for multiclass classification of an imbalanced dataset that makes a successful model that both trains and evaluates the model and prints the Accuracy, Precision, Recall, and F1 score. Data will be in the form of a CSV file with 600,000 samples (or rows in the CSV) of 15 classes (for y_train and y_test) and 78 input dimensions/features. The imbalance will have some classes that have a low of only 8 samples taken. Your job...
Consider a Convolutional Neural Network which accepts a 120 x 120 CMYK image as input. The...
Consider a Convolutional Neural Network which accepts a 120 x 120 CMYK image as input. The network has a series of 5 convolutional layers, where the parameters in conv-layer 3 and conv-layer 5 are shared. Each conv-layer has 20 3x3 filters. The output of the last conv-layer is flattened and passed through a fully connected layer with 30 neurons, which is then passed through another fully connected layer of 10 neurons. Each neuron in the fully connected layers and each...
In this assignment you will start with Python code that builds a 2 host network connected...
In this assignment you will start with Python code that builds a 2 host network connected by a legacy router. You will modify it such that the two hosts can send packets to each other. It requires that you understand subnet addressing and the function of a router. The network built using Miniedit on a Mininet virtual machine: python mininet/examples/miniedit.py. We need to also make 6 static routes to make the program work. This is the work that I have...
Create the appropriate 2 x 2 table for the data. Include appropriate row and column labels and complete the table with information provided in the scenario.
A. Researchers conducted a case control study to identify the association between alcohol consumption and esophageal cancer among men. They enrolled 187 men with esophageal cancer and 715 men without esophageal cancer. The men were asked about their regular alcohol consumption and the men were categorized as either drinking ≥80 g/day (exposed) or
Write out the addition and multiplication tables for the ring Z2[x]/(x^2 + x). Is Z2[x]/(x^2 +...
Write out the addition and multiplication tables for the ring Z2[x]/(x^2 + x). Is Z2[x]/(x^2 + x) a field?
Q.  Show that the ellipse x^2/4+ y^2/9= 1 in R2 is connected, and show that the function...
Q.  Show that the ellipse x^2/4+ y^2/9= 1 in R2 is connected, and show that the function f(x, y) = 3 x^3− 5y^3 − 4 has a zero on the above ellipse.
Find the equation of the tangent line at x=2 to the graph of y= x^2-x-7 Write...
Find the equation of the tangent line at x=2 to the graph of y= x^2-x-7 Write your answer as a simplified slope-intercept equation y=mx+b. For example   y=7x-8
1. Write the set { x | x ∈ R, x2 = 4 or x 2...
1. Write the set { x | x ∈ R, x2 = 4 or x 2 = 9} in list form. 2. {x: x is a real number between 1 and 2} is an a) finite set b) empty set c) infinite set 3. Write set {1, 5, 15, 25,…} in set-builder form. 4. What is the cardinality of each of these sets? a) {{a}} b) {a, {a}} c) {a, {a}, {a, {a}}} d) {∅} e) {∅, {∅}, {∅, {∅}}}...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT