close

[Solved] module ‘tensorflow._api.v2.train’ has no attribute ‘GradientDescentOptimizer’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error module ‘tensorflow._api.v2.train’ has no attribute ‘GradientDescentOptimizer’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How module ‘tensorflow._api.v2.train’ has no attribute ‘GradientDescentOptimizer’ Error Occurs?

Today I get the following error module ‘tensorflow._api.v2.train’ has no attribute ‘GradientDescentOptimizer’ in python.

How To Solve module ‘tensorflow._api.v2.train’ has no attribute ‘GradientDescentOptimizer’ Error ?

  1. How To Solve module 'tensorflow._api.v2.train' has no attribute 'GradientDescentOptimizer' Error ?

    To Solve module 'tensorflow._api.v2.train' has no attribute 'GradientDescentOptimizer' Error In TensorFlow 2.0, Keras became the default high-level API, and optimizer functions migrated from tf.keras.optimizers into separate API called tf.optimizers.

  2. module 'tensorflow._api.v2.train' has no attribute 'GradientDescentOptimizer'

    To Solve module 'tensorflow._api.v2.train' has no attribute 'GradientDescentOptimizer' Error In TensorFlow 2.0, Keras became the default high-level API, and optimizer functions migrated from tf.keras.optimizers into separate API called tf.optimizers.

Solution 1

In TensorFlow 2.0, Keras became the default high-level API, and optimizer functions migrated from tf.keras.optimizers into separate API called tf.optimizers. They inherit from Keras class Optimizer. Relevant functions from tf.train aren’t included into TF 2.0. So to access GradientDescentOptimizer, call tf.optimizers.SGD

Solution 2

You are using Tensorflow 2.0. The following code will be helpful:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read