tensorflow.keras.sequential.add
时间: 2023-10-31 16:09:52 浏览: 90
The `add()` method in `tensorflow.keras.Sequential` class is used to add layers to the neural network model sequentially. Each layer is added one after the other in the order they are specified.
For example, to create a simple neural network with two hidden layers, we can use the `add()` method to add each layer to the model:
```python
import tensorflow as tf
model = tf.keras.Sequential()
# Adding the first hidden layer with 64 units and ReLU activation function
model.add(tf.keras.layers.Dense(64, activation='relu'))
# Adding the second hidden layer with 32 units and ReLU activation function
model.add(tf.keras.layers.Dense(32, activation='relu'))
# Adding the output layer with 10 units and softmax activation function
model.add(tf.keras.layers.Dense(10, activation='softmax'))
```
In this example, we first create an empty `Sequential` model and then use the `add()` method to add three layers to it. The first two layers are hidden layers with ReLU activation functions, and the last layer is the output layer with softmax activation function.
阅读全文