Question: Consider the following code lines ( DONT USE AI ) : import numpy as np import matplotlib.pyplot as plt from tensorflow import keras from tensorflow.keras
Consider the following code lines DONT USE AI:
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 keras.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 keras.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
Answer these questions:
Question 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 function.
What if you want h to represent a constant function that always outputs x
Question:
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 numbers
Run your answer before submit
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
