Deep Learning for Mechanical Engineering

Homework 10

Due Wed., 11/29/2023, 4:00 PM


Prof. Seungchul Lee
http://iailab.kaist.ac.kr/
Industrial AI Lab at KAIST
  • 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.

    • Ensure that your NAME and student ID are included in your .ipynb files. ex) IljeokKim_20202467_HW08.ipynb
  • Compress all the files into a single .zip file.

    • In the .zip file's name, include your NAME and student ID. ex) DogyeomPark_20202467_HW08.zip
    • Submit this .zip file on KLMS
  • Do not submit a printed version of your code, as it will not be graded.

Problem 1: LSTM with TensorFlow¶

  • 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.



In [ ]:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

(1) Load MNIST Data

  • Download MNIST data from the tensorflow tutorial example
In [ ]:
## 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)
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11490434/11490434 [==============================] - 0s 0us/step
train_x:  (60000, 28, 28)
test_x:  (10000, 28, 28)

(2) Plot a ramdomly selected data with its label

In [ ]:
## your code here
#

(3) Define LSTM Structure



In [ ]:
## your code here
#
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 lstm (LSTM)                 (None, 14, 10)            1560      
                                                                 
 lstm_1 (LSTM)               (None, 10)                840       
                                                                 
 dense (Dense)               (None, 100)               1100      
                                                                 
 dense_1 (Dense)             (None, 28)                2828      
                                                                 
=================================================================
Total params: 6,328
Trainable params: 6,328
Non-trainable params: 0
_________________________________________________________________

(4) Define Cost, Initializer and Optimizer Loss

  • Regression: Squared loss
$$ \frac{1}{N} \sum_{i=1}^{N} (\hat{y}^{(i)} - y^{(i)})^2$$

Initializer

  • Initialize all the empty variables

Optimizer

  • AdamOptimizer: the most popular optimizer
In [ ]:
## your code here
#

(5) Define optimization configuration and then optimize

In [ ]:
## your code here
#
0.0014543014112859964
0.0032421338837593794
0.008472677320241928
0.00035746616777032614
0.001835529925301671
0.010492042638361454
0.0002733171568252146
0.0002736546448431909
0.0003306472790427506
0.00020183045126032084
0.00015898968558758497

(6) Test or Evaluate

  • Predict the MNIST image
  • 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, then the model predict the last 14 x 28 image, recursively.
In [ ]:
## your code here
#

Problem 2¶

  • 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.