tf.keras.optimizers.SGD()
时间: 2024-05-09 09:20:50 浏览: 9
SGD stands for Stochastic Gradient Descent, which is a popular optimization algorithm used in deep learning. It is an iterative method that updates the parameters of the model based on the gradient of the loss function with respect to those parameters.
The tf.keras.optimizers.SGD() function is used to create an optimizer object for optimization using stochastic gradient descent. It takes several parameters, such as learning rate, momentum, and decay rate, that determine how the optimizer updates the model parameters during training.
Example Usage:
```
from tensorflow.keras.optimizers import SGD
optimizer = SGD(learning_rate=0.01, momentum=0.9, nesterov=True)
model.compile(optimizer=optimizer, loss='mse')
```
In this example, we create an SGD optimizer with a learning rate of 0.01, momentum of 0.9, and Nesterov momentum enabled. We then compile the model with this optimizer and a mean squared error loss function.