Question: Anaswer question P 1 . 3 , P 2 . 3 , P 3 . 1 and P 3 . 2 . ( Dont write
Anaswer question P P P and PDont write description, just codeAlso review these codes and find the isuse. Check the following code lines DONT USE AI against these questions and modify if any issue is there.
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
xtrain, ytrainxtest, ytest mnist.loaddata
xtrain xtrain.astypefloat
xtest xtest.astypefloat
xtrain npexpanddimsxtrain,
xtest npexpanddimsxtest,
inputshape xtrain.shape:
numclasses
epochs
def buildmlpmodel:
model Sequential
layers.Flatteninputshapeinputshape
layers.Dense activation"relu"
layers.Dense activation"relu"
layers.Dense activation"relu"
layers.Dense activation"relu"
layers.Dense activation"relu"
layers.Dense activation"relu"
layers.Densenpprodinputshape activation"sigmoid"
layers.Reshapeinputshape
return model
mlpmodel buildmlpmodel
mlpmodel.compileoptimizersgd loss"mse"
mlpmodel.summary
mlphistory mlpmodel.fitxtrain: xtrain: epochsepochs, batchsize verbose
pltplotmlphistory.historyloss
plttitleMLP Training Loss'
pltxlabelEpoch
pltylabelLoss
pltshow
def buildcnnmodel:
model Sequential
layers.ConvD kernelsize activation'relu', padding'same', inputshapeinputshape
layers.ConvDinputshape kernelsize activation'sigmoid', padding'same'
return model
cnnmodel buildcnnmodel
cnnmodel.compileoptimizersgd loss"mse"
cnnmodel.summary
cnnhistory cnnmodel.fitxtrain: xtrain: epochsepochs, batchsize verbose
pltplotcnnhistory.historyloss
plttitleCNN Training Loss'
pltxlabelEpoch
pltylabelLoss
pltshow
W npeyeinputshape
W npeye
W npeye
b npzeros
b npzeros
b npzerosinputshape
b nponesinputshape xtrain
def buildidentitycnnmodel:
model keras.Sequential
layers.ConvDinputshape kernelsize activation'linear', padding'same', inputshapeinputshape
return model
def buildidentityrelucnnmodel:
model keras.Sequential
layers.ConvDinputshape kernelsize activation'relu', padding'same', inputshapeinputshape
return model
Answer these questions:
P Implement a fully connected neural network h:xup tox model that regresses an image into itself. The architecture should have trainable dense layers: the first layers with neurons and ReLU activation, and an output layer with the necessary number of units and activation.
P Train the model using SGD on the appropriate loss function for epochs on the training data. Plot the training loss over epochs.
P Plot the prediction over the training set and test set you should spot a pattern in the predictions, but since there is some randomness associated with using the GPU we recommend repeating the training times to be sure you pick up the right pattern Which function do you conjecture hx has learnt write it in formula
P Implement a CNN g:xup tox
model that regresses an image into itself. The architecture should have convolutional layers: the first with filters, kernel size x
and the same output size as input, and the second a convolutional output layer with the necessary number of filters, kernel and activation.
P Train the model using SGD on the appropriate loss function for epochs on the training data. Plot the training loss over ephocs.
Pexaclty the same as P but for gx
P Consider a multilayer ReLU network h: Rn up to Rn such that hx WReLUWReLUWxbbb with Was an element ofRa x n Was an element of R n x a Was an element of Rn x n bas element of Ra; b bas element of Rn Find a possible solution for W W W b b b such that h represents the identity funct
What if you want h to represent a constant function that always outputs x
P Consider a CNN g: Rn x n up to Rn x n model composed by a first hidden convolutional layer with c filters, d x d d odd kernel, identity activation and a suitable convolutional output layer. Find a possible architecture for g ie specify the complete architecture, c the values in the filters, padding and stride such that g represents the identity function.
If instead of the identity activation, we use a ReLU activation, how should the architecture change?
Note: R for set of real
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
