Python Tensorflow._api.v2.train 没有属性“AdamOptimizer”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/55318273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:33:38  来源:igfitidea点击:

Tensorflow._api.v2.train has no attribute 'AdamOptimizer'

pythontensorflow

提问by MatlabNewb

When using

使用时

model.compile(optimizer = tf.train.AdamOptimizer(),
              loss = 'sparse_categorical_crossentropy',
              metrics=['accuracy'])

in my Jupyter Notebook the following Error pops up:

在我的 Jupyter Notebook 中,弹出以下错误:

module 'tensorflow._api.v2.train' has no attribute 'AdamOptimizer'

模块“tensorflow._api.v2.train”没有属性“AdamOptimizer”

Tensorflow Version: 2.0.0-alpha0

Tensorflow 版本:2.0.0-alpha0



Do you think the only possibility is to downgrade the TF version?

你认为唯一的可能就是降级TF版本吗?

回答by William G

I haven't tried 2.0 yet, but from what I've seen on the dev submit videos, you can use

我还没有尝试过 2.0,但从我在开发提交视频中看到的,你可以使用

model.compile(optimizer = 'adam',
           loss = 'sparse_categorical_crossentropy',
           metrics=['accuracy'])

回答by Rriskit

tf.optimizers.Adam()

Is the way to go. No reason to downgrade.
There are lots of changes in tf 2.0 compared to 1.14.
Note that the parameter-names of Adam have changed, too. e.g. beta1 is now beta_1, check the documentation in Meixu Songs link.

是要走的路。没有理由降级。
与 1.14 相比,tf 2.0 有很多变化。
请注意,Adam 的参数名称也已更改。例如 beta1 现在是 beta_1,请查看 Meixu Songs 链接中的文档。

回答by ShaneCalder

model.compile(optimizer = tf.keras.optimizers.Adam(),
              loss = 'sparse_categorical_crossentropy',
              metrics=['accuracy'])

回答by MrRex

I had the same error. I removed

我有同样的错误。我删除了

tf.train.AdamOptimizer() 

And I wrote

我写了

tf.optimizers.Adam()

Instead.

反而。

回答by Adi

It's a minor change in upgraded version.

这是升级版的一个小改动。

Please use:

请用:

model.compile(optimizer=tf.optimizers.Adam(), loss="sparse_categorical_crossentropy")

Thanks!

谢谢!