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.
In this problem, you will make a LSTM model to predict the half of an MNIST image using the other half.
You will split an MNIST image into 28 pieces.
MNIST is 28 x 28 image. The model predicts a piece of 1 x 28 image.
First, 14 x 28 image will be feeded into a model as time series, then the model predict the last 14 x 28 image, recursively.
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
(1) Load MNIST Data
## provided
(train_imgs, train_labels), (test_imgs, test_labels) = tf.keras.datasets.mnist.load_data()
train_imgs = train_imgs/255.0
test_imgs = test_imgs/255.0
print('train_x: ', train_imgs.shape)
print('test_x: ', test_imgs.shape)
(2) Plot a ramdomly selected data with its label
## your code here
#
(3) Define LSTM Structure
## your code here
#
(4) Define Cost, Initializer and Optimizer Loss
Initializer
Optimizer
## your code here
#
(5) Define optimization configuration and then optimize
## your code here
#
(6) Test or Evaluate
## your code here
#
In this problem, we have bearing data with 3 classes (healthy, inner fault, outer fault).
The objective is to classify the given data using deep learning models.
Dataset Description
The bearing data is collected by a sensory system which has 2 channels: vibration and rotational speed. You can refer to the paper to see the specification in detail. The experimental setup is shown in the below figure. The dataset contains 36 files with 3 classes, 2 sensor positions, and 4 speed varying conditions. Every data is sampled at 200,000 Hz of sampling frequency and 10 seconds of duration. We will use only the increasing speed condition and the channel 1 (vibration data) for the sake of simplicity.
Download & Load Data
We already made the data ready for you. You can download the data in .npy format. Three files are prepared for a train set and three files for a test set.
(1) Plot all data
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from google.colab import drive
drive.mount('/content/drive')
Healthy_train = np.load('/content/drive/MyDrive/DL_Colab/DL_data/Bearing_Healthy_train.npy')
InnerFault_train = np.load('/content/drive/MyDrive/DL_Colab/DL_data/Bearing_InnerFault_train.npy')
OuterFault_train = np.load('/content/drive/MyDrive/DL_Colab/DL_data/Bearing_OuterFault_train.npy')
Healthy_test = np.load('/content/drive/MyDrive/DL_Colab/DL_data/Bearing_Healthy_test.npy')
InnerFault_test = np.load('/content/drive/MyDrive/DL_Colab/DL_data/Bearing_InnerFault_test.npy')
OuterFault_test = np.load('/content/drive/MyDrive/DL_Colab/DL_data/Bearing_OuterFault_test.npy')
## your code here for training dataset
#
## your code here for test dataset
#
In the following subproblems, you will be introduced deep learning models which are used for time-series data classification. You are asked to build the model with the given architecture and evaluate the performance.
Various deep learning models for time-series data classification
In the deep learning field, there are plenty of models for time-series data classification. Compared to conventional machine learning algorithms, recent deep neural network models show much higher accuracy as you can see in the table below. In this problem, we will build the CNN-LSTM model whose elements are covered in this course.
Implementation of CNN-LSTM model
The CNN-LSTM model is introduced in "An Improved Bearing Fault Diagnosis Method using One-Dimensional CNN and LSTM." The authors combined 1D CNN and LSTM succesfully and it shows high performance in terms of both computation time and accuracy. The following configuration shows a part of the structure of the model. The model takes the segmented data as an input. A data segment which has a length of 2,000 is randomly cropped from the original time-series data.
(2) Create trainset and testset
Create trainset and testset to feed the model you designed. Set the number of segments equals to 4,000 for trainset and 1,000 for testset (for each class).
## your code here
#
(3) Build the model based on the above information and print the structure.
Build the model based on the above information and print the structure. You can freely assign the other parameters that are not described in the above configuration in order to achieve better performance. (You don't need to refer the original paper for those.) Please refer to the summary of the model structure.
You will use the 1D convolution layer for this problem. We have learned 2D convolution in class and 1D convolution is nothing but 2D convolution with a height as 1.
Input_shape of data = (4000, 2000, 1)
2000 $\rightarrow$ 20 $\times$ 100 $\rightarrow$ CNN layers $\rightarrow$ LSTM layer
## your code here
#
(4) Train the model and print the training procedure.
## your code here
#
(5) Evaluate the model in terms of accuracy of the testset.
## your code here
#
(6) Build new model without 1DCNN, train it with the data you used for CNN+LSTM model, and test it with the test dataset used previously
## your code here
#
## your code here
#
## your code here
#
(7) Compare loss and accuracy curves of two models (one with LSTM only and the other with CNN+LSTM)
Note that two models do not show big difference in terms of the accuarcy due to the simplicity of dataset.
## your code here
#
## your code here
#