---
# System prepended metadata

title: 機器學習 入門(X 認識(O 03
tags: [ML]

---

---
tags: ML
---

機器學習 入門(X 認識(O 03
===
https://hackmd.io/NKAOz3geTqijBhR9r82RZw
### 笑話開場
神探狄仁傑向妻子抱怨道：「現在天道不彰，仁道不行，我名字之中有個仁字又有何用?」妻子道：「你跟我說這個幹嘛?」神探回答：「如果我是狄傑，你會愛我嗎?」

### (簽到區)
幫我用留言功能簽到
# 複習
### 監督式學習
1. 載入資料 
>csv,xlxs...
2. 建立模型
>DNN,CNN...
4. 訓練模型
>次數,時間....
5. 測試
>over fiting
### DNN
模組化輸出

# 補充
Dropout
```python=
model.add(Dropout(0.2))
```

### back propragation

# CNN
總圖
![](https://2.bp.blogspot.com/-lo4ANmafiQM/WVpEeo68VPI/AAAAAAAAWxE/7FJBUGp-GrQFL5fUYEg6tQAJWXUHrtgWgCLcBGAs/s1600/3812_1.png)
## 概念
白板->

## convolution 

![](https://www.researchgate.net/profile/Chaim_Baskin/publication/318849314/figure/fig1/AS:614287726870532@1523469015098/Image-convolution-with-an-input-image-of-size-7-7-and-a-filter-kernel-of-size-3-3.png)

filter 數量?

1 filter = 1 種特徵

## max pool

降低資料大小
![](https://www.google.com/url?sa=i&url=https%3A%2F%2Fpaperswithcode.com%2Fmethod%2Fmax-pooling&psig=AOvVaw1nplEqCwt7EKQlM8bsF51b&ust=1607003001838000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCICM7Oq2r-0CFQAAAAAdAAAAABAI)

## Flatten

展開為一維，並接上NN

>Flatten就是攤平之後，給你百八十個參數輸入，接上全連接層的腿
## 統整
![image alt](https://www.jefkine.com/assets/images/conv.png)

### back propragation
白板->
# 實戰

[機器學習02](https://hackmd.io/TAYAmalVTsKzzUrjLAZs_g)
https://keras.io/zh/layers/convolutional/
```python=
def load_data():#
  (X_train, Y_train), (X_test, Y_test) = kr.datasets.mnist.load_data()
  x_train = X_train.reshape(60000, 1, 28, 28)/255
  x_test = X_test.reshape(10000, 1, 28, 28)/255
  y_train = np_utils.to_categorical(Y_train)
  y_test = np_utils.to_categorical(Y_test)
  return (x_train, y_train), (x_test, y_test)
```


```python=
model.add(Conv2D(filters=32, kernel_size=3, input_shape=(1, 28, 28), activation='relu', padding='same'))
model.add(MaxPool2D(pool_size=2, data_format='channels_first'))
model.add(Flatten())
```
原本
```python=
cv2_imshow(x_test[i])
```

改成
```python=
cv2_imshow((x_test[i]*255).reshape(28,28))
```
filters:filter 的數量
kernel_size: kernel的大小 只設一個的話就是都一樣
activation:你知道的
padding:填充

### 儲存模型

```python=
model.save('my_model.h5')
```

### 載入模型
```python=
new_model=kr.models.load_model('my_model.h5')
new_model.summary()
los=model.evaluate(x_test,y_test)
```

## 參考
https://blog.gtwang.org/programming/keras-save-and-load-model-tutorial/
https://medium.com/@CinnamonAITaiwan/%E6%B7%B1%E5%BA%A6%E5%AD%B8%E7%BF%92-cnn%E5%8E%9F%E7%90%86-keras%E5%AF%A6%E7%8F%BE-432fd9ea4935

