---
# System prepended metadata

title: Keras 神經網路的開發步驟
tags: [Keras, Deep Learning]

---

# Keras 神經網路的開發步驟
1. 定義訓練資料: Input Tensor, Target Tensor
2. [定義網路層 (Layers)](https://hackmd.io/1W0c-6JPSP2YUyh4gK0jVQ)
3. [選擇損失函數、優化器](https://hackmd.io/YP19VRsnTGyXMjWniuQyJA)
4. 呼叫模型的 `fit()`

# 定義模型的方法

- 序列式(Sequential)
```python=
network = models.Sequential()
network.add(layers.Dense(32, activation='relu', input_shape=(784,)))
network.add(layers.Dense(10, activation='softmax'))
```
- 函數式(Functional)
```python=
input_tensor = layers.Input(shape=(784,))
x = layers.Dense(10, activation='relu')(input_tensor)
output_tensor = layers.Dense(10, activation=)(x)
model = models.Model(inputs=input_tensor, output=output_tensor)
```

# 編譯模型的方法

```python=
from keras import optimizers
model.compile(
    optimizer=optimizers.RMSprop(lr=0.001)),
    loss='mse',
    metrics=['accuracy']
)
```

# 模型學習的方法
```python=
model.fit(input_tensor, target_tensor, batch_size=128, epochs=10)
```

###### tags: `Keras` `Deep Learning` 