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
(x_train, y_train),(x_test, y_test)= mnist.load_data()
x_train = x_train.astype("float32")/255.0
x_test = x_test.astype("float32")/255.0
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)
input_shape = x_train.shape[1:]
num_classes =10
epochs =1000
def build_mlp_model():
model = keras.Sequential([
layers.Flatten(input_shape=input_shape),
layers.Dense(4, activation="relu"),
layers.Dense(4, activation="relu"),
layers.Dense(4, activation="relu"),
layers.Dense(4, activation="relu"),
layers.Dense(4, activation="relu"),
layers.Dense(4, activation="relu"),
layers.Dense(np.prod(input_shape), activation="sigmoid"),
layers.Reshape(input_shape)
])
return model
mlp_model = build_mlp_model()
mlp_model.compile(optimizer="sgd", loss="mse")
mlp_model.summary()
mlp_history = mlp_model.fit(x_train[:1], x_train[:1], epochs=epochs, batch_size=1, verbose=1)
plt.plot(mlp_history.history['loss'])
plt.title('MLP Training Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.show()
def build_cnn_model():
model = keras.Sequential([
layers.Conv2D(10, kernel_size=(5,5), activation='relu', padding='same', input_shape=input_shape),
layers.Conv2D(input_shape[-1], kernel_size=(1,1), activation='sigmoid', padding='same')
])
return model
cnn_model = build_cnn_model()
cnn_model.compile(optimizer="sgd", loss="mse")
cnn_model.summary()
cnn_history = cnn_model.fit(x_train[:1], x_train[:1], epochs=epochs, batch_size=1, verbose=1)
plt.plot(cnn_history.history['loss'])
plt.title('CNN Training Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.show()
Answer these questions:
Question1- Consider a multilayer ReLU network h: R^n (up to) R^n such that h(x)= W3ReLU(W2ReLU(W1x+b1)+b2)+b3 with W1(as an element of)R^a x n, W2(as an element of) R^ n x a, W3(as an element of) R^n x n, b1(as element of )R^a; b2, b3(as element of ) R^n. Find a possible solution for W1, W2, W3, b1, b2, b3 such that h represents the identity function.
What if you want h to represent a constant function that always outputs x0?
Question2:
P3.2- Consider a CNN g: R^n x n (up to) R^n x n model composed by a first hidden convolutional layer with c filters, d x d (d>1 odd) kernel, identity activation and a suitable convolutional output layer. Find a possible architecture for g (i.e. 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!