Hands-on tutorial of deep learning (Keras)Chun-Min Chang
Summary
# Fundamentals of deep learning
--- selection of activation function
--- selection of loss function
--- selection of optimizer
--- effect of learning rate
# How to prevent overfitting
--- Regularization
--- Dropout
--- Early stopping
--- Batch Normalization
Hands-on tutorial of deep learning (Keras)Chun-Min Chang
Summary
# Fundamentals of deep learning
--- selection of activation function
--- selection of loss function
--- selection of optimizer
--- effect of learning rate
# How to prevent overfitting
--- Regularization
--- Dropout
--- Early stopping
--- Batch Normalization
Introduction to Basic Haskell Components (In Chinese)ChengHui Weng
In 2012, we had the first Chinese functional meetup about general functional programming techniques in Taipei. I gave this talk to introduce several classes in the famous Typeclassesopedia article.
在此課程中將帶領對資料分析感到陌生卻又充滿興趣的您,完整地學會運用 R 語言從最初的蒐集資料、探索性分析解讀資料,並進行文字探勘,發現那些肉眼看不見、隱藏在資料底下的意義。此課程主要設計給對於 R 語言有基本認識,想要進一步熟悉實作分析的朋友們,希望在課程結束後,您能夠更熟悉 R 語言這個豐富的分析工具。透過蘋果日報慈善捐款的資料集,了解如何從頭解析網頁,撰寫爬蟲自動化收集資訊;取得資料後,能夠靈活處理資料,做清洗、整合及探索;並利用現成的套件進行文字探勘、文本解析;我們將一步步實際走一回資料分析的歷程,處理、觀察、解構資料,試著看看人們在捐款的決策過程中,究竟是什麼因素產生了影響,以及這些結果又是如何從資料中挖掘而出的呢?
2. 目錄
前言----------------------------------------------------------------------------------------P.3
Introduction of Deep Learning I ----------------------------------------------P.6
Step 1--------------------------------------------------------------------------------P.8
Step 2--------------------------------------------------------------------------------P.13
Step 3--------------------------------------------------------------------------------P.17
Introduction of Deep Learning II -----------------------------------------------P.20
Introduction of Deep Learning III ----------------------------------------------P.25
類神經網路建立 ------------------------------------------------------------------------
P.32
CNN ---------------------------------------------------------------------------------P.33
RNN ----------------------------------------------------------------------------------P.63
Keras實做手寫辨識-------------------------------------------------------------------P.85
50. CNN實作練習
建置一個CNN網路分辨手寫辨識字
引用函數並且從網路下載mnist 手寫數據庫
Code[ part 1]:
from __future__ import print_function
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
# number 1 to 10 data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
51. CNN實作練習
建置一個CNN網路分辨手寫辨識字
定義準確度函數
Code[ part 2]:
def compute_accuracy(v_xs, v_ys):
global prediction
y_pre = sess.run(prediction, feed_dict={xs: v_xs, keep_prob: 1})
correct_prediction = tf.equal(tf.argmax(y_pre,1), tf.argmax(v_ys,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
result = sess.run(accuracy, feed_dict={xs: v_xs, ys: v_ys, keep_prob: 1})
return result
87. Keras實作練習
建置一個手寫辨識
首先匯入 Keras 及相關模組:
Code[ part 1]:
import numpy as np
import pandas as pd
import sys, os
from keras.utils import np_utils
from keras.datasets import mnist
np.random.seed(10)
88. Keras實作練習
建置一個手寫辨識
讀取與查看 mnist 資料
可知道 training data 共有 60,000 筆; testing data 共有 10,000 筆
Code[ part 2]:
(X_train_image, y_train_label), (X_test_image, y_test_label) = mnist.load_data()
print("t[Info] train data={:7,}".format(len(X_train_image)))
print("t[Info] test data={:7,}".format(len(X_test_image)))
print("t[Info] Shape of train data=%s" % (str(X_train_image.shape)))
print("t[Info] Shape of train label=%s" % (str(y_train_label.shape)))
89. Keras實作練習
建置一個手寫辨識
定應 plot_image 函數顯示數字影像
Code[ part 3]:
def isDisplayAvl():
return 'DISPLAY' in os.environ.keys()
import matplotlib.pyplot as plt
def plot_image(image):
fig = plt.gcf()
fig.set_size_inches(2,2)
plt.imshow(image, cmap='binary')
plt.show()
90. 建立 plot_images_labels_predict() 函數
後續我們希望能很方便查看數字圖形, 所以我們建立了以下函數:
Code[ part 4]:
def plot_images_labels_predict(images, labels, prediction, idx, num=10):
fig = plt.gcf()
fig.set_size_inches(12, 14)
if num > 25: num = 25
for i in range(0, num):
ax=plt.subplot(5,5, 1+i)
ax.imshow(images[idx], cmap='binary')
title = "l=" + str(labels[idx])
if len(prediction) > 0:
title = "l={},p={}".format(str(labels[idx]), str(prediction[idx]))
else:
title = "l={}".format(str(labels[idx]))
ax.set_title(title, fontsize=10)
ax.set_xticks([]); ax.set_yticks([])
idx+=1
plt.show()
96. Keras實作練習
建置一個手寫辨識
評估模型準確率 、進行預測
Code[ part 10]:
print("t[Info] Making prediction to x_Test_norm")
prediction = model.predict_classes(x_Test_norm) # Making prediction and save result to prediction
print()
print("t[Info] Show 10 prediction result (From 240):")
print("%sn" % (prediction[240:250]))
if isDisplayAvl():
plot_images_labels_predict(X_test_image, y_test_label, prediction, idx=240)
print("t[Info] Error analysis:")
for i in range(len(prediction)):
if prediction[i] != y_test_label[i]:
print("tAt %d'th: %d is with wrong prediction as %d!" % (i, y_test_label[i], prediction[i]))
print()