AttributeError: 'module' object has no attribute 'TFOptimizer'

1,674 views
Skip to first unread message

adityaku...@gmail.com

unread,
Sep 20, 2018, 1:41:44 AM9/20/18
to Keras-users
tf version 1.10.1

For the following code :

lr = keras.backend.variable(0.01)
tf_opt = tf.train.GradientDescentOptimizer(learning_rate=lr)
opt = keras.optimizers.TFOptimizer(tf_opt)
opt.lr = lr


Obtain error :
---> 22 opt = keras.optimizers.TFOptimizer(tf_opt) 23 opt.lr = lr 24 AttributeError: 'module' object has no attribute 'TFOptimizer'

Matias Valdenegro

unread,
Sep 20, 2018, 2:08:18 AM9/20/18
to keras...@googlegroups.com

What matters is which Keras version do you have?

 

On Thursday, 20 September 2018 07:41:44 CEST adityaku...@gmail.com wrote:

> tf version 1.10.1

>

> For the following code :

>

> lr = keras.backend.variable(0.01)

> tf_opt = tf.train.GradientDescentOptimizer(learning_rate=lr)

> opt = keras.optimizers.TFOptimizer(tf_opt)

> opt.lr = lr

>

>

> Obtain error :

> ---> 22 <https://localhost:8080/#> opt = keras.optimizers.TFOptimizer(tf_opt

adityaku...@gmail.com

unread,
Sep 20, 2018, 1:41:03 PM9/20/18
to Keras-users
I imported keras from tensorflow.
Following is the version :
keras.__version__ = 2.1.6-tf

adityaku...@gmail.com

unread,
Sep 20, 2018, 1:48:17 PM9/20/18
to Keras-users
I even downloaded the source code for version 2.1.6 and checked optimizers.py, and it contained the class TFOptimizer. Unable to debug this error.

adityaku...@gmail.com

unread,
Sep 20, 2018, 1:50:34 PM9/20/18
to Keras-users
Even checked the source code for keras 2.1.6, and the optimizers.py file did contain the class TFOptimizer. Unable to debug this error.


On Thursday, September 20, 2018 at 1:08:18 AM UTC-5, Matias Valdenegro wrote:

Matias Valdenegro

unread,
Sep 20, 2018, 3:45:43 PM9/20/18
to keras...@googlegroups.com

Ok, but you didn't had to write three emails about it.

 

I checked the source code and TFOptimizer in keras inside tensorflow is not marked as exported (no tf_export tag), that's why you get an error.

 

But if you install keras from pip and import it, it works fine. Seems an error in the keras version inside tensorflow.

adityaku...@gmail.com

unread,
Sep 22, 2018, 1:11:02 PM9/22/18
to Keras-users
Apologies for that. Did not find my first response posted, due to some lag. So replied back again.

Thanks for looking into the code.

from tensorflow.python.keras.optimizers import TFOptimizer
Importing manually like this did the job.
Reply all
Reply to author
Forward
0 new messages