Week_4
Week_4
8 Convolution Neural Networks for Image Classification (Oxford Pets, Tiny ImageNet, etc.)
9 Recurrent Neural Networks for Sentiment Analysis with IMDB Movie Reviews
10 Long Short Term Memory for Stock Prices (Yahoo Finance API)
List of Experiments contd.
Week # Experiment Title
𝑥0
𝑤0 = 1
𝑥1 𝑤1
4
𝑤2
𝑥2 𝑧 = 𝑥𝑖 𝑤𝑖 𝑦 ′ = 𝜑(𝑧) 𝑦′
𝑤3 𝑖=0
𝑥3
𝑤4
𝑥4
MLP
Forward Pass
1 1 1
3
1 𝑤01
𝑤01 2
𝑤01 𝑂13
3 𝜃13
2 𝑤02
𝑤02 3
1 1 𝑤11
𝑤11 𝑤02 2
𝑤11
𝑥1 𝜃11 𝜃12 3
𝑤12
1
𝑤12 2
𝑤12
3
𝑤21 𝑂23
3
𝑤22 𝜃23
1 2
𝑤21 𝑤21
1 2
𝑤22 𝑤22
𝑥2 𝜃21 𝜃22
0 1 2 3
Back Propagation
MNIST Dataset
The MNIST dataset (Modified National Institute of Standards and Technology) is
one of the most well-known datasets in the field of machine learning and computer
vision
def create_model():
model = tf.keras.Sequential([
tf.keras.layers.Dense(512, activation='relu', input_shape=(784,)),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
return model
from tensorflow.keras.utils import plot_model
tf.keras.utils.plot_model(
model,
to_file="model.png",
show_shapes=True,
MLP Visualization
show_layer_names=True,
rankdir="TB",
expand_nested=False,
dpi=96,
)
def train(model, x_train, y_train, x_test, y_test): The model will train for 20 epochs,
# Train the model meaning it will process the entire
history = model.fit(x_train, y_train, training dataset 20 times
batch_size=128,
epochs=20,
validation_split=0.2,
𝐵1 𝐵2 𝐵3 𝐵4 𝐵𝑛
verbose=1)
1 1 1 1 1
2 2 2 2 2
3 3 3 3
⋯ 3
... ... ... ... ...
128 128 128 128 128
MLP for Image Classification
MLP for Image Classification
Week 4 Exercises
1.MLP Classifier for MNIST Handwritten Digits
Objective: To build, train, evaluate, and visualize the performance of an MLP image
classifier using the MNIST dataset.