For your handwritten solutions, please scan or take a picture of them. Alternatively, you can write them in markdown if you prefer.
Only .ipynb files will be graded for your code.
Compress all the files into a single .zip file.
Do not submit a printed version of your code, as it will not be graded.
As we have learned in the lectures, Convolutional Neural Networks (CNN) have the capability to classify images directly. This characteristic makes CNN highly versatile and applicable to a wide range of industries. In this particular task, we aim to employ CNN for the classification of sign language. This application will enable individuals to engage in direct communication with those who are hearing impaired, even if they are not familiar with sign language.
(1) Load and plot 6 random data points. You need to load a total of 4 files.
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from google.colab import drive
drive.mount('/content/drive')
# Change file paths if necessary
train_x = np.load('/content/drive/MyDrive/DL_Colab/DL_data/sign_language_train_img.npy')
train_y = np.load('/content/drive/MyDrive/DL_Colab/DL_data/sign_language_train_label.npy')
test_x = np.load('/content/drive/MyDrive/DL_Colab/DL_data/sign_language_test_img.npy')
test_y = np.load('/content/drive/MyDrive/DL_Colab/DL_data/sign_language_test_label.npy')
# check the shape of data
print(train_x.shape)
print(train_y.shape)
print(test_x.shape)
print(test_y.shape)
## your code here
#
(2) Design your CNN structure and train it with the training data.
## your code here
#
model.compile(optimizer = 'adam',
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
model.fit(train_x, train_y, epochs = 20)
(4) Test your model. Calculate accuracy and plot a random image with its predicted and true label.
## your code here
#
## your code here
#
Let's build a CNN model that classifies steel surface defects.
Download NEU steel surface defects images and labels
(1) Load and plot 3 random images for 6 classes.
# Change file paths if necessary
train_x = np.load('/content/drive/MyDrive/DL_Colab/DL_data/NEU_train_imgs.npy')
train_y = np.load('/content/drive/MyDrive/DL_Colab/DL_data/NEU_train_labels.npy')
test_x = np.load('/content/drive/MyDrive/DL_Colab/DL_data/NEU_test_imgs.npy')
test_y = np.load('/content/drive/MyDrive/DL_Colab/DL_data/NEU_test_labels.npy')
print(train_x.shape)
print(train_y.shape)
print(test_x.shape)
print(test_y.shape)
name = ['scratches', 'rolled-in scale', 'pitted surface', 'patches', 'inclusion', 'crazing']
plt.figure(figsize = (12,7))
## your code here
#
(2) Design your CNN structure and train it with the training data.
$\quad$Note:
## your code here
#
model.compile(optimizer = tf.keras.optimizers.Adam(0.001),
loss = 'sparse_categorical_crossentropy',
metrics = ['accuracy'])
model.fit(train_x, train_y, epochs = 20)
(4) Test your model. Compute accuracy and plot a random image with its predicted and true label.
## your code here
#
## your code here
#
(5) Visualize the feature maps in convolutional layers 1 through 5.
outputs = [layer.output for layer in model.layers]
outputs
test_img = test_x[0]
plt.figure(figsize = (4,4))
plt.imshow(test_img.reshape(200, 200), 'gray')
plt.axis('off')
plt.show()
## your code here
#