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.

PLEASE WRITE CODE AND DO NOT SENT ME DIFFERENT PARTS TO A WEBSITE.

It is clear, it's a homework assignment.  

Solutions

Expert Solution

#loading library
import tensorflow as tf
from tensorflow.keras.layers import Conv2D, MaxPooling2D, BatchNormalization
from tensorflow.keras.layers import Dropout, Flatten, Input, Dense

#loading dataset
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

#Normalization of dataset
train_images = train_images / 255.0
test_images = test_images / 255.0


#creating the model
def create_model():
    
    def add_conv_block(model, num_filters):
        
        model.add(Conv2D(num_filters, 3, activation='relu', padding='same'))
        model.add(BatchNormalization())
        model.add(Conv2D(num_filters, 3, activation='relu', padding='valid'))
        model.add(MaxPooling2D(pool_size=2))
        model.add(Dropout(0.2))

        return model
    
    model = tf.keras.models.Sequential()
    model.add(Input(shape=(28, 28, 3)))
    
    model = add_conv_block(model, 32)
    model = add_conv_block(model, 64)
    model = add_conv_block(model, 128)

    #flattening the model
    model.add(Flatten())
    model.add(Dense(3, activation='softmax'))

    #compiling the model
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

model = create_model()
model.summary()

#fitting the training dataset
model.fit(train_images, train_labels, epochs=10)

test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)
print('\nTest accuracy:', test_acc)

Related Solutions

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...
Predictive Modeling Using Neural Networks (For SAS Enterprise Miner software) In preparation for a neural network...
Predictive Modeling Using Neural Networks (For SAS Enterprise Miner software) In preparation for a neural network model, is the imputation of missing values needed? Why or why not?
what does resent50 function do in neural network ?
what does resent50 function do in neural network ?
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...
Briefly assess the relationships between Biological and Artificial Neural Network
Briefly assess the relationships between Biological and Artificial Neural Network
In a    network topology, all network devices are connected to a common backbone that serves as...
In a    network topology, all network devices are connected to a common backbone that serves as a shared communications medium.
Subject: Neural network and Pattern recognition (Deep Learning) Given the following partial network definitioon: Input -...
Subject: Neural network and Pattern recognition (Deep Learning) Given the following partial network definitioon: Input - A 28 x 28 RGB image First Layer - 7, 5 x 5 filters. Activation function: Sigmoid Second Layer - 23, 3 x 3 filters. Activation function: RelU Third Layer - 20, 3 x 3 filters. Activation function: RelU You task is to do design(s) of the next part of the network (so that it uses the output of the third layer). The purpose...
Say that a neural network has been constructed to predict the creditworthiness of applicants. There are...
Say that a neural network has been constructed to predict the creditworthiness of applicants. There are two output nodes: one for yes (1 = yes, 0 = no) and one for no (1 = no, 0 = yes). An applicant receives a score of 0.83 for the “yes” output node and a 0.44 for the “no” output node. Discuss what may have happened and whether the applicant is a good credit risk. explain with your own words please
short essay describe how a neural network function. include the " use it or lose it"...
short essay describe how a neural network function. include the " use it or lose it" concept and the description of how individual cells work to transmit information. 2) you are driving a car. describe the functions of the various parts of your nervous system, including brain structures, are performing. include at least ten parts of the nervous system in your description.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT