1 of 104

AI人工智慧深度學習奇幻之旅_2

李柏翰

leepohan@gmail.com

14 August, 2021

*

1

2 of 104

*

2

20210807_AI_奇幻之旅_1.ppt

https://sites.google.com/d/1ENTFZWjhdQkF-mqHingOQpPdpvfuZsbt/p/168xrzn4XiKJhggiHTksJQUhdVQsUBl0D/edit

20210814_AI_奇幻之旅_2.ppt

https://docs.google.com/presentation/d/1oLufCDeql3uglu51gPlnsRbG0L-T3fT0/edit?usp=sharing&ouid=105523845726996386023&rtpof=true&sd=true

PPT 下載

3 of 104

*

3

AI教學的 ppt and code

https://sites.google.com/d/1ENTFZWjhdQkF-mqHingOQpPdpvfuZsbt/p/168xrzn4XiKJhggiHTksJQUhdVQsUBl0D/edit

https://sites.google.com/view/buzznote/p1

4 of 104

*

4

1. 利用google Colab來學習,機器學習,深度學習。

2. Anaconda 3 安裝。

3. 簡易Python code 語法說明。

4. 利用Python實作 CNN卷積神經網路的深度學習。

5. 第一支自己的CNN Python code,贏在起跑點。

6. 如何深化自己在機器學習,深度學習的領域。

大綱

Anaconda 3 安裝

CNN卷積神經網路

CNN, Tommy

5 of 104

*

5

https://medium.com/@hiskio/生成對抗網路到底在gan麻-f149efb9eb6b

1.什麼是AI,ML,DL

6 of 104

*

6

30年深度學習的孤獨之旅!2018年圖靈獎「AI三巨頭」

認識AI三巨頭

Geoffrey Hinton 深度學習,卷積神經網路CNN之父

Yann LeCun 推動深度學習(DL),(pics from Wikipedia)

Yoshua Bengio,Learning Deep Architectures for AI

7 of 104

*

7

機器學習分類

8 of 104

*

8

SGDRegressor

Elastic Net

Gradient Boosting

Tree

XGBoost

Linear SVM

支援向量機

Naïve Bayes

樸素貝葉斯

Decision Tree

決策樹

Random Forest

隨機森林

監督式學習

迴歸

監督式學習

分類

非監督式學習

集群

K-means 分群

K-modes

(K眾數聚類)

機器學習分類方法

9 of 104

*

9

迴歸: 解決問題的方式是預測出一個實際值, ex. 預測溫度、房價、PM2.5含量等

分類:想要判定某事物的類別

🡺 產出結果並非精確數值,稱為類別標籤 (Label),常見的分類法有 KNN決策樹

機器學習迴歸與分類

Linear SVM

支援向量機

10 of 104

*

10

機器學習流程

定義問題

蒐集資料

資料前處理

訓練模型

模型預測

https://www.youtube.com/watch?v=nKW8Ndu7Mjw

11 of 104

*

11

https://www.youtube.com/watch?v=nKW8Ndu7Mjw

機器學習(ML)

The 7 steps of machine learning

12 of 104

*

12

CNN,卷積神經網路的概念,DL

13 of 104

*

13

https://cs.stanford.edu/people/karpathy/convnetjs/index.html

ConvNetJS Deep Learning in your browser (DL)

CNN: (Convolutional neural network),卷積神經網路的概念,DL網頁實作

14 of 104

*

14

https://cs.stanford.edu/people/karpathy/convnetjs/demo/mnist.html

ConvNetJS MNIST demo

Javascript 在瀏覽器中的MNIST 數字數據集,訓練卷積神經網絡。

數據集相當簡單,應該期望在幾分鐘內達到 99% 左右的準確率。

15 of 104

*

15

28x28 MNIST 圖像並進行訓練,在隨機的 24x24 窗口。

與預測類似,並對所有作的概率進行平均以產生最終預測

在 Ubuntu+Chrome 機器上,以大約 5 毫秒的速度運行,向前和向後傳遞。

這個演示中,使用 Adadelta,參數自適應步長方法,不必擔心隨著時間的推移改變學習率或動量

ConvNetJS MNIST demo

卷積層

激活層

池化層

16 of 104

*

16

卷積層

激活層

池化層

激活層

全連接層

CNN卷積神經網路

損失函數

17 of 104

*

17

2. Anaconda 3 安裝

18 of 104

*

18

https://walker-a.com/archives/6260

Anaconda 3 下載與安裝

19 of 104

*

19

Anaconda 3 安裝

20 of 104

AI & Python 自我精進

*

20

  1. 基本功:莫煩Python ( https://mofanpy.com/ )

21 of 104

*

21

基本功 1:莫煩Python ( https://mofanpy.com/ )

22 of 104

*

22

基本功 2:K 書

23 of 104

*

23

基本功 2:K 書

24 of 104

*

24

基本功 2:K 書

25 of 104

*

25

和AI做朋友

https://www.openedu.tw/course.jsp?id=876

26 of 104

*

26

2-1 CNN 常見網站介紹

27 of 104

*

27

TensorFlow Playground是個好幫手

https://playground.tensorflow.org/

28 of 104

*

28

CNN卷積神經網路,贏在起跑點

29 of 104

*

29

https://www.youtube.com/watch?v=aircAruvnKk

DL,深層神網路的概念

30 of 104

*

30

https://www.youtube.com/watch?v=IHZwWFHWa-w&t=769s

梯度下降,尋找最小誤差路徑

31 of 104

*

31

https://poloclub.github.io/cnn-explainer/

CNN,卷積神經的DL

32 of 104

*

32

3. 簡易Python code 語法說明。

33 of 104

*

33

開啟Spyder IDE 介面

34 of 104

*

34

# 1-1.py 邏輯運算子

a,b,c=5,10,6

result1= a>b and b>c # and 且運算

result2= a<b or c!=a # or 或運算

print(result1) ; print(result2) # 輸出結果

False

True

1-1.py 邏輯運算子

35 of 104

*

35

##1-2.py

print("Please input one number:")

score = int(input())

if score >= 60 :

print("Pass") # if 需要將程序往後空格

else:

print("Fail")

Please input one number:

64

Pass

1-2.py if結構

36 of 104

*

36

##1-3.py

total=0

for count in range(1,101):

total+=count

print("1+2+3...+100=",total)

1+2+3...+100= 5050

 

37 of 104

*

37

##1-4.py

total=0

for count in range(1,100,2):

total+=count

print("1+3+5...+99=",total)

1+3+5...+99= 2500

 

38 of 104

*

38

##1-5.py

x,y=1,10

while x<y:

x+=1 # x = x + 1

print(x)

10

1-5.py while迴圈

39 of 104

*

39

##1-6.py

total=0

for i in range(1,201,2):

if i==101:

break # 跳脫迴圈

total+=i

print("1~100奇數和",total)

1~100奇數和 2500

1-6.py break指令

40 of 104

*

40

##1-7.py

for x in range(1,10):

if x==5:

continue # 跳脫本輪迴圈

print(x,end= " ")

1 2 3 4 6 7 8 9

1-7.py continue指令

41 of 104

*

41

##1-8.py 印出元素

List1=["A","B","C","D","E"]

for i in range(len(List1)):

print(List1[i])

A B C D E

1-8.py list結構

42 of 104

*

42

##1-9.py 印出最大

a=[3,8,4] # a=[ ] 陣列

print(max(a)) # 印出最大

a.sort() # 排序

print(a) # 印出a

8

[3, 4, 8]

1-9.py 挑最大數字

43 of 104

*

43

##1-10.py 印出最小

a=[3,8,4] # a=[ ] 陣列

print(min(a)) # 印出最小

a.sort() # 排序

print(a) # 印出a

3

[3, 4, 8]

1-10.py 挑最小數字

44 of 104

*

44

##1-11.py

word1= "zoo"

word2="animal"

print("交換前:",word1,word2)

word2,word1 = word1,word2 #Unpacking

print("交換後:",word1,word2)

交換前: zoo animal

交換後: animal zoo

1-11.py Unpacking

45 of 104

*

45

##1-12.py

def func(a,b,c) :

x=a+b+c

print(x)

print(func(1,2,3))

6

None

1-12.py 函數

46 of 104

*

46

##1-13.py

L1=[1,3,5,7]

T1=tuple(L1)

print(T1)

(1, 3, 5, 7) # 注意:小括號表示型態為元組,tuple

1-13.py 元組tuple

47 of 104

*

47

##1-14.py

STR ="Hello Python, This is Program"

print("STR字串長:", len(STR))

print(list(STR[4:8]))

print("元素3出現的位置-->", list(STR[3]))

STR字串長: 29

['o', ' ', 'P', 'y']

元素3出現的位置--> ['l']

1-14.py 切割字串

48 of 104

*

48

##1-15.py

def Pow(x,y):

p=1;

for i in range(y+1):

p*=x

return P

x,y=2,10

print(pow(x,y))

1-15.py 建立函式,解2的10次方

1024

49 of 104

*

49

4. 利用Python實作 CNN卷積神經網路的深度學習

Scikit Learn

Talk_v2_code

50 of 104

*

50

可以學習Scikit Learn

機器學習、資料科學的工具庫,利用Python程式語法撰寫的函式庫, Sklearn

51 of 104

*

51

1. Supervised learning

52 of 104

*

52

下載Scikit Learn code

53 of 104

*

53

Run Scikit Learn code

Digit_code

Linear_code

Classification_code

54 of 104

*

54

5. 第一支自己的CNN Python code,贏在起跑點。

https://drive.google.com/file/d/1UerrnA59Nw747syHQkBFvilheftwRhcA/view?usp=sharing

mnist_using_keras.ipynb

mnist_using_pytorch.ipynb

https://drive.google.com/file/d/1glMAHwZPyAxEBTyShSAzo7-nD61pOA4V/view?usp=sharing

55 of 104

*

55

4. 利用Python實作 CNN卷積神經網路的深度學習

第1個 Side Project:

數字辨識 by keras

mnist_using_keras .ipynb

56 of 104

*

56

感知器是甚麼?

Collaboratively administrate empowered markets via plug-and-play networks.

W1:權重(weight) / W2:權重

b: 偏權值 / O: 稱作『神經元』或『節點』

感知器式收到多個輸入號之後,再將訊號整合,在輸出一個訊號

O: 神經元

57 of 104

*

57

深度學習: 建立在多層感知器

猜數字AI訓練,學會參數是多少個

4. softmax

數值轉換成小數點,以機率表示

28x28=784

3. ReLU函數:

(activation function)

58 of 104

*

58

Step 1: import

載入數字資料集

59 of 104

*

59

Step2 : Plot number

60 of 104

*

60

Step3 : Scaling 0~1

61 of 104

*

61

Step4 : One-hot encoding

62 of 104

*

62

Step4 : Bulid model

63 of 104

*

63

Step4 : model Summary

參數 784X16 + 16 = 12560

數目 16X32 + 32 = 544

32X64 + 64 = 2112

64X10 + 10 = 650

ML DL 就是訓練參數,幾個參數至關重要

64 of 104

*

64

Step5 : model.fit

65 of 104

*

65

Step5 : 訓練結果

66 of 104

*

66

Step6 : 訓練好,做預測

67 of 104

*

67

Step 7: Loss function

68 of 104

*

68

Step 8: Accuracy

69 of 104

*

69

Step 9: Prediction

預測為7,成功辨識

70 of 104

*

70

6. 如何深化自己在機器學習,深度學習的領域。

https://sites.google.com/view/buzznote/p1

71 of 104

*

71

第2個 Side Project:

鳥鳴聲: 可以利用自然語言學習嗎?�從鳥類生理時期分類 開始

72 of 104

*

72

斯氏繡眼之生理時期

  • 巢前期: 目標於巢前鳴叫之時期。
  • 築巢期: 目標築巢之時期。
  • 抱卵期: 目標抱卵之時期。
  • 巢外育: 於巢外育養幼鳥時之時期。
  • 產蛋期: 目標產蛋時鳴叫之時期。
  • 育雛期: 在巢內育養幼鳥時之時期。
  • 雛失敗: 目標育養之幼鳥去世後鳴叫之時期。

綠繡眼

https://iconada.tv/profiles/blogs/sihuo055

73 of 104

*

73

斯氏繡眼資料集

錄音資料集來自鳥人孫清松先生,經切割、刪除後:

  • 300 timesteps (約10secs)
  • 30 minutes

74 of 104

*

74

研究目的

利用機器學習訓練出模型解決:

  • 鳥類生理時期辨識問題
  • 鳥類物種辨識問題

並找出解決問題的最佳模型解

75 of 104

*

75

研究流程

訓練資料集

  • 斯氏繡眼資料集
  • XC資料集

76 of 104

*

76

Xeno-Canto資料集

  • A, B 等級品質
  • 18種鳥類
  • 大部分為鳴禽�(雀形亞目)
  • 共約55GB
  • 450~1800 timestep

(15~60secs)

https://www.xeno-canto.org/

77 of 104

*

77

78 of 104

*

78

資料預處理

  • Mel spectrogram
  • MFCC

梅爾倒頻譜係數 (MFCC)

聲紋圖

79 of 104

*

79

Conv1D-based Module 卷積模型

80 of 104

*

80

循環神經網路(RNN, Recurrent Neural Network)

  • 串聯各Timestep
  • 具時間記憶性

LSTM、GRU

(長短期記憶模型)

記憶特徵更長

81 of 104

*

81

Attention mechanism

82 of 104

*

82

Model

83 of 104

*

83

Loss function

- Training

- Validation

84 of 104

*

84

斯氏繡眼鳥類生理時期分類

85 of 104

*

85

斯氏繡眼生理時期分類

Confusion Matrix

86 of 104

*

86

Transformer

87 of 104

*

87

模型示意圖

Transformer Encoder

BERT-based Module

88 of 104

*

88

XC鳥種辨識預測

89 of 104

*

89

XC鳥種辨識 Confusion Matrix

90 of 104

*

90

生理時期 & XC鳥種辨識 預測

91 of 104

*

91

斯氏繡眼生理時期聲音預測

92 of 104

*

92

斯氏繡眼生理時期Confusion Matrix

93 of 104

*

93

驗證: t-SNE 降維視覺化

  • 非線性的機器學習降維方法
  • 降維時保持局部結構能力佳

! 不同種間的範圍大小與距離無關

94 of 104

*

94

斯氏繡眼生理時期:降維驗證

95 of 104

*

95

Attention map 權重視覺化

  • 取 <CLS> Token 之權重
  • 看出模型注意到的聲音區塊
  • 不同Head有不同特徵注意點

96 of 104

*

96

Attention map 權重視覺化

97 of 104

*

97

XC 鳥種辨識Confusion Matrix

98 of 104

*

98

機器學習面臨的問題

  • 監督式學習Label問題
  • 資料集大小、品質、環境變因(錄音地點等)
  • 資料標注(同時間多隻鳥發聲等)

綠繡眼

https://iconada.tv/profiles/blogs/sihuo055

99 of 104

*

99

鳥鳴聲:結論

  • 斯氏繡眼生理時期會發出不同鳴聲是可以預測的,F1 score = 97.78%
  • 鳥鳴聲與自然語言(NLP)之相似度極高。
  • 18種相同/相近鳥種之鳴聲特徵相似,是可以預測的,F1 score = 79.00%
  • NLP 的Transformer and Attention是可以用來預測鳥鳴聲。

100 of 104

*

100

鳥鳴聲:未來展望

  • 比較不同物種之關係。
  • 建立親緣關係樹或行為物種間學習關係圖 。
  • 聲音特徵符號化/語言化之可能性。
  • 鳥聲生成&對話。
  • 鳥類醫學、鳥類資料集建構。
  • 以應用程式包裝廣泛利用。

101 of 104

*

101

結論

  • 利用google Colab來學習 ML DL。
  • 您知道什麼是AI,機器學習,深度學習
  • 利用網路資源,進入機器學習(Machine Learning),深度學習(Deep Learning)。
  • TensorFlow Playground是個好幫手
  • CNN,贏在起跑點。
  • 機器學習,深度學習可以做很多。
  • Scikit Learn 您必須會。

102 of 104

*

102

今日您學會的課程

1.利用google Colab來學習

2. Anaconda 3 安裝

3. 簡易Python code 語法說明

4. 利用Python 實作 CNN卷積神經網路的深度學習。

5. 第一支自己的CNN Python code,贏在起跑點。

6. 如何深化自己在機器學習,深度學習的領域。

103 of 104

*

103

https://docs.google.com/forms/d/e/1FAIpQLSfRM5UAmxNSdIgTB9XRJrAiOn7mpHjHpJ15hI-NLd-8psXO0A/viewform

今天第二周的課程,您滿意嗎?

請填問卷

104 of 104

*

104

Thanks for attention